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 個答案
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
專家
已回答 7 個月前
  • 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
專家
已回答 7 個月前
0

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

profile picture
專家
已回答 7 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南