Someone to kindly help me in this template. I am trying to signal Cloudformation using cfn-signal on my instance with a logical id MyInstance. This is the error I am getting after trying to debug it all day.
AWSTemplateFormatVersion: 2010-09-09
Description: Creating an ec2 instance
Parameters:
ParamKeyName:
Description: Select the key name from the list
Type: AWS::EC2::KeyPair::KeyName
ParamAZName:
Description: Select the key name from the list
Type: AWS::EC2::AvailabilityZone::Name
ParamInstanceType:
Description: Select the Instance Type from the list
Type: String
Default: t3.small
AllowedValues:
- t2.micro
- t3.small
- t3.micro
Resources:
MySG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow HTTP and SSH traffic
GroupName: Dev SecurityGroup
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: '80'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
MyInstance:
Type: AWS::EC2::Instance
CreationPolicy:
ResourceSignal:
Timeout: PT10M
Metadata:
"AWS::CloudFormation::Init":
configSets:
setup:
- myec2config
myec2config:
packages:
yum:
httpd: []
files:
"/var/www/html/index.html":
content: |
<h1>Hello from Restart</h1>
mode: "000755"
owner: root
group: root
services:
sysvinit:
httpd:
enabled: true
ensureRunning: true
Properties:
ImageId: ami-093467ec28ae4fe03
SecurityGroups:
- !Ref MySG
KeyName: !Ref ParamKeyName
AvailabilityZone: !Ref ParamAZName
InstanceType: !Ref ParamInstanceType
Tags:
- Key: Name
Value: EC2 Instance
UserData:
'Fn::Base64':
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource MyInstance --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource MyInstance --region ${AWS::Region}
Outputs:
OutputAppURL:
Description: App URL
Value: !Sub 'http://${MyInstance.PublicDnsName}'