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ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ