Create AMI image as part of a cloudformation stack

后端 未结 4 591
温柔的废话
温柔的废话 2020-12-08 14:42

I want to create an EC2 cloudformation stack which basically can be described in the following steps:

1.- Launch instance

2.- Provision the instance

4条回答
  •  广开言路
    2020-12-08 15:20

    While @wjdordan's solution is good for simple use cases, updating the User Data will not update the AMI.

    (DISCLAIMER: I am the original author) cloudformation-ami aims at allowing you to declare AMIs in CloudFormation that can be reliably created, updated and deleted. Using cloudformation-ami You can declare custom AMIs like this:

    MyAMI:
      Type: Custom::AMI
      Properties:
        ServiceToken: !ImportValue AMILambdaFunctionArn
        Image:
          Name: my-image
          Description: some description for the image
        TemplateInstance:
          ImageId: ami-467ca739
          IamInstanceProfile:
            Arn: arn:aws:iam::1234567890:instance-profile/MyProfile-ASDNSDLKJ
          UserData:
            Fn::Base64: !Sub |
              #!/bin/bash -x
              yum -y install mysql # provisioning example
              # Signal that the instance is ready
              INSTANCE_ID=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
              aws ec2 create-tags --resources $INSTANCE_ID --tags Key=UserDataFinished,Value=true --region ${AWS::Region}
          KeyName: my-key
          InstanceType: t2.nano
          SecurityGroupIds:
          - sg-d7bf78b0
          SubnetId: subnet-ba03aa91
          BlockDeviceMappings:
          - DeviceName: "/dev/xvda"
            Ebs:
              VolumeSize: '10'
              VolumeType: gp2
    

提交回复
热议问题