Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0ef29ab52ff72213b
InstanceType: t2.micro
KeyName: niikawa-testkey
UserData:
Fn::Base64: !Sub |
#!/bin/bash
sudo hostnamectl set-hostname niikawa-test-linux
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
Encrypted: false
DeleteOnTermination: true
Iops: 3000
SnapshotId: snap-0xxxxxxxxxxxxxxxx
VolumeSize: 10
VolumeType: gp3
Throughput: 125
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeviceIndex: 0
GroupSet:
- sg-0xxxxxxxxxxxxxxxx
SubnetId: subnet-xxxxxxxx
CreditSpecification:
CPUCredits: standard
Tags:
- Key: Name
Value: niikawa-test-ec2
IamInstanceProfile:
Arn: arn:aws:iam::111111111111:instance-profile/niikawa-ec2-ssm
MetadataOptions:
HttpEndpoint: enabled
HttpPutResponseHopLimit: 2
HttpTokens: required
PrivateDnsNameOptions:
HostnameType: ip-name
EnableResourceNameDnsARecord: false
EnableResourceNameDnsAAAARecord: false
Reasoning: {The provided AWS CLI command creates an EC2 instance with the specified properties like image ID, instance type, key pair, user data script, EBS volume, network interface, CPU credit specification, tags, IAM instance profile, metadata options, and private DNS name options. I have mapped each of these properties to the corresponding CloudFormation resource properties under the AWS::EC2::Instance resource type. The UserData property is base64 encoded as required by CloudFormation. The BlockDeviceMappings property is defined as a list with a single mapping for the root EBS volume. The NetworkInterfaces property is defined as a list with the specified subnet ID, security group, and public IP assignment. The count parameter from the CLI is not needed in CloudFormation as it will create the specified number of resources by default.}