CI/CD for EC2 AMIs

0

Hi AWS, I am deploying an application (.NET 4.7 Web app) on Windows instance using GitHub Actions. Now as soon as the application is deployed on to the server I need to create AMI of latest VM. How that will be possible using GitHub Actions as we have decided to not use AWS CodePipeline for the same.

Please suggest if you have any demo working samples repo.

3 Answers
2

Hello. You can use this step inside your github actions.

    - name: Create AMI
      run: |
        INSTANCE_ID="YOUR_INSTANCE_ID" # replace with your instance's ID
        AMI_NAME="MyApp-$(date +'%Y-%m-%d-%H-%M-%S')"

        # Create AMI
        IMAGE_ID=$(aws ec2 create-image --instance-id $INSTANCE_ID --name "$AMI_NAME" --description "An AMI for MyApp" --no-reboot --query 'ImageId' --output text)
        echo "AMI ID: $IMAGE_ID"

Regards, Andrii

profile picture
EXPERT
answered 7 months ago
  • Hi Andrii S, thanks I got that as well. But now I have one more question I need to create this AMI only if there are some updates on the server. For e.g. installed two more DLLs or software. How can we acknowledge that and create an AMI with the updates?

1

If you want to create an AMI automatically whenever you make updates to an EC2 instance, you can take several approaches.

Using AWS Systems Manager (SSM) AWS Systems Manager allows you to automate tasks across AWS resources. You can use Systems Manager Run Command to automate the creation of AMIs.

Trigger with CloudWatch Events AWS CloudWatch Events can be used to detect changes in your EC2 instances and then trigger the Systems Manager Run Command.

Because it`s not possible to integrate GitHub action to automatically create an AMI.

Regards, Andrii

profile picture
EXPERT
answered 7 months ago
0

Could you please accept the answer if it helped for you? Thanks)

profile picture
EXPERT
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions