The UserData
section of my EC2Instance
resource has the following:
#!/bin/bash
apt-get update -y
apt-get -y install python3-pip
mkdir -p /opt/aws/
pip3 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz
ln -s /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup
/usr/local/bin/cfn-init -v --stack ${AWS::StackId} --resource EC2Instance --configsets server_install --region ${AWS::Region}
/usr/local/bin/cfn-signal -e $? --stack ${AWS::StackId} --resource EC2Instance --region ${AWS::Region}
While running the stack creation process, I noticed that the cfn-init
and the cfn-signal
commands failed to run because my EC2 didn't have any of the packages I installed through AWS::Cloudformation:Init
.
I logged on to the server to check things out (NOTE: logging on to the server after a failed stack build is only possible if you don't revert stack upon failure or don't signal for failures) and I found the following errors:
/var/log/cloud-init.log:
2023-04-12 21:17:17,121 - subp.py[DEBUG]: Running command
['/var/lib/cloud/instance/scripts/part-001'] with allowed return codes [0] (shell=False, capture=False)
2023-04-12 21:28:34,625 - subp.py[DEBUG]: Unexpected error while running command.
Command: ['/var/lib/cloud/instance/scripts/part-001']
Exit code: 1
Reason: -
Stdout: -
Stderr: -
2023-04-12 21:28:34,629 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
/var/lib/cloud/instance/scripts/part-001: Same UserData
section from CF template
/var/log/cloud-init-output.log:
2023-04-12 21:18:06,101 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-east-1.amazonaws.com
2023-04-12 21:18:06,102 [DEBUG] Describing resource EC2Instance in stack arn:aws:cloudformation:us-east-1:<accountId>:stack/<app-name>/<uuid>
2023-04-12 21:19:06,102 [WARNING] Timeout of 60 seconds breached
2023-04-12 21:19:06,103 [ERROR] Client-side timeout
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/cfnbootstrap/util.py", line 193, in _retry
return f(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/cfnbootstrap/util.py", line 266, in _timeout
raise TimeoutError(
cfnbootstrap.util.TimeoutError
2023-04-12 21:18:06,101 [DEBUG] CloudFormation client initialized with endpoint https://cloudformation.us-east-1.amazonaws.com
2023-04-12 21:18:06,102 [DEBUG] Signlaing resource EC2Instance in stack arn:aws:cloudformation:us-east-1:<accountId>:stack/<app-name>/<uuid>
2023-04-12 21:19:06,102 [WARNING] Timeout of 60 seconds breached
2023-04-12 21:19:06,103 [ERROR] Client-side timeout
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/cfnbootstrap/util.py", line 193, in _retry
return f(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/cfnbootstrap/util.py", line 266, in _timeout
raise TimeoutError(
cfnbootstrap.util.TimeoutError