cloudformation to create ec2 using volume attachment for root.
Hello I am trying to create one EC2 using cloudformation. The requirement is to use volume attachment with a snapshot id. This snapshot id is coming from my AMI and the snapshot id provided is the root device. (AMI only consist of one snapshot)
I got the error message: Property ImageId cannot be empty when deploying the resource. When I input the ImageId for AWS::EC2::Instance, it will crash with AWS::EC2::VolumeAttachment property.
Can someone help to modify my template and point out how can I fix this issue?
---
Description: "AWS CloudFormation sample template. Create a new EC2 instance"
Resources:
myEC2Instance:
Properties:
IamInstanceProfile: ec2role
InstanceType: t2.micro
SecurityGroupIds:
- sg-123456
SubnetId: subnet-123456
Tags:
-
Key: Name
Value: ec2test
Type: "AWS::EC2::Instance"
myMountPoint:
Properties:
Device: /dev/xvda
InstanceId: myEC2Instance
VolumeId: myVolume
Type: "AWS::EC2::VolumeAttachment"
myVolume:
Properties:
AvailabilityZone: !GetAtt myEC2Instance.AvailabilityZone
Size: 10
SnapshotId: snap-123456
Tags:
-
Key: Name
Value: ebstest
VolumeType: gp2
Size: 10
Type: "AWS::EC2::Volume"
I think you may have a simple syntax error here.
Have a look at the YAML code snippet on this page: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-ebs-volumeattachment.html
You need to use !Ref to reference the names of the other resources.
Hope this helps
Relevant questions
How to create IoT x509 certificate using CloudFormation?
Accepted Answerasked 3 months agoTag Specific Volume in a Multi-Volume Launch Template
asked 6 months agoCreate Route via Cloudformation Template
asked 4 months agoEc2 Instance stuck in stopping - Can't change volume
asked 6 months agoIs there a way to identify an EBS Volume inside a Linux EC2 instance using its volume ID ?
asked 4 months agoEC2 Image Builder updating Launch Templates and wiping Snapshot configuration
asked 7 months agocloudformation to create ec2 using volume attachment for root.
asked a month agoIn order to shrink the root volume of the AWS EBS
asked 2 months agoCan't delete EBS volume, not even with the force option
Accepted Answerasked 7 months agoSnapshot of EBS volume created from snapshot
asked 3 years ago