DEV Community

Cover image for CodePipeline EC2 Action: Simplify your EC2 application deployment pipeline by 90%!
19 2 3 3 3

CodePipeline EC2 Action: Simplify your EC2 application deployment pipeline by 90%!

Amazon Web Services (AWS) CodePipeline Team has simplified Developer, DevOps engineers operational overhead and streamlined the Deployment process to EC2 by introducing an CodePipeline action to deploy directly to your EC2 instances.

Why does it matter to you?

Previously, if you wanted to deploy to EC2 instances, you had to use CodeDeploy with an AppSpec file to configure the deployment. After this update NO NEED TO MANAGE CODEDEPLOY RESOURCE AND APPSPEC FILE.

I tried this out today so let me show you how you can simplify your deployment pipeline by 90% and remove all the complex process and scripts!!!

Architecture

architecture diagram

Prerequisites

  • supports only Linux instance types
  • maximum fleet size supported is 500 instances.
  • Pipeline V2 only supported
  • SSM Agent must be installed

Behind the Scenes

This action performs a send-command using SSM to execute the script in the instance.

ssm behind the scenes

Create an EC2 instance with Apache

Note: If you are creating an instance then you need to create a role with AmazonSSMManagedInstanceCore, AmazonS3ReadOnlyAccess and attach to ec2 instance.

  • Add ssm agent to the instance manually either using user data or logging into existing instance and then running the commands.

  • If you are using existing instance then you need to reboot the instance after adding the ssm agent.

I have created EC2 with Apache web server for the brevity of the blog.

shell commands for running apache

sudo su
yum update -y
yum install httpd -y
service httpd start
chkconfig httpd on
echo "codepipeline ec2 deployment action" > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

apache webserver output

Create pipeline with Ec2 deployment action

pipeline deploy config

  • Here we need to select instance using tags; I have used name tag to identify my instance.
  • Then you need to provide the target directory in ec2 instance where you want to deploy.
  • Finally path to the executable script file that runs AFTER the Deploy phase.

Note: Once pipeline is created you need to edit the pipeline service role and add the following permissions to avoid error.

        {
            "Effect": "Allow",
            "Action": [
                "ssm:CancelCommand",
                "ssm:DescribeInstanceInformation",
                "ssm:ListCommandInvocations",
                "ssm:SendCommand"
            ],
            "Resource": "*"
        }
Enter fullscreen mode Exit fullscreen mode

codepipeline service role

Run the pipeline

I am using the source as GitHub using code start connection and code resides in this repo.

Note: The aws guide mentioned about adding AWSSystemsManagerDefaultEC2InstanceManagementRoleeployAction to the ec2 instance role but in my environment I didn't needed that permission

Pipeline execution

Webserver after update

Some advanced options for this action

advanced options for action

  • You can specify number of instances in number or percentages to deploy to in parallel.
  • You can specify number of instances in number or percentages to stop the task after the task fails.
  • You can specify load balancer which will block the traffic Toi the instance when deployment is taking for that instance.

From Developer, DevOps perspective

  • With this update I can have an END-to-END AWS native Continuous deployment on EC2 without managing CodeDeploy resources.
  • This is surely a game changer for developers and devops engineers who wants to focus on business problem, their applications and not on their complex deployment process.
  • Of course this experience of simplifying can be augmented even further to 100% if AWS can add necessary permissions for the role.

After reading this, do you wish to migrate to this action and simplifying your deployment process? Let me know in the comments!!!

I share such amazing AWS updates on DevOps, Kubernetes and GenAI daily over Linkedin, X. Follow me over there so that I can make your life more easy.

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (2)

Collapse
 
lfelipe1501 profile image
Luis Felipe Sanchez Sanchez

Good post.

Collapse
 
jatinmehrotra profile image
Jatin Mehrotra

Glad you liked it.

Will you use this action for your EC2 deployment? Let me know how is the operational overhead

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay