- create an
app.props
file as follows -
AppName=jhw-hello-world
justin@justin-XPS-13-9360:~/work$ ./describe_stacks.sh
--------------------------------------------------------------------------------
| DescribeStacks |
+-----------------------------------------------------------+------------------+
| 1.Name | 2.Status |
+-----------------------------------------------------------+------------------+
| #{an_existing_stack} | UPDATE_COMPLETE |
+-----------------------------------------------------------+------------------+
justin@justin-XPS-13-9360:~/work$ ./deploy_stack.sh jhw-keypair-x240 # <-- pre- exising key pair with .pem file stored in `~/.ssh/id_rsa`
Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - jhw-hello-world
justin@justin-XPS-13-9360:~/work$ ./describe_stacks.sh
--------------------------------------------------------------------------------
| DescribeStacks |
+-----------------------------------------------------------+------------------+
| 1.Name | 2.Status |
+-----------------------------------------------------------+------------------+
| jhw-hello-world | CREATE_COMPLETE |
| #{an_existing_stack} | UPDATE_COMPLETE |
+-----------------------------------------------------------+------------------+
justin@justin-XPS-13-9360:~/work$ ./describe_events.sh
--------------------------------------------------------------------------------------------------------------------------------------------------------------
| DescribeStackEvents |
+--------------------------+---------------------------------+-----------------------------------------+---------------------+-------------------------------+
| 1.Timestamp | 2.Id | 3.Type | 4.Status | 5.Reason |
+--------------------------+---------------------------------+-----------------------------------------+---------------------+-------------------------------+
| 2019-10-25T10:19:43.010Z| jhw-hello-world | AWS::CloudFormation::Stack | CREATE_COMPLETE | None |
| 2019-10-25T10:19:41.478Z| AppEC2Instance | AWS::EC2::Instance | CREATE_COMPLETE | None |
| 2019-10-25T10:19:26.211Z| AppEC2Instance | AWS::EC2::Instance | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:19:25.046Z| AppEC2Instance | AWS::EC2::Instance | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:19:23.622Z| AppInstanceProfile | AWS::IAM::InstanceProfile | CREATE_COMPLETE | None |
| 2019-10-25T10:18:00.605Z| AppSubnetRouteTableAssociation | AWS::EC2::SubnetRouteTableAssociation | CREATE_COMPLETE | None |
| 2019-10-25T10:17:45.351Z| AppSubnetRouteTableAssociation | AWS::EC2::SubnetRouteTableAssociation | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:45.063Z| AppRoute | AWS::EC2::Route | CREATE_COMPLETE | None |
| 2019-10-25T10:17:44.820Z| AppSubnetRouteTableAssociation | AWS::EC2::SubnetRouteTableAssociation | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:43.418Z| AppSubnet | AWS::EC2::Subnet | CREATE_COMPLETE | None |
| 2019-10-25T10:17:42.684Z| AppVPCGatewayAttachment | AWS::EC2::VPCGatewayAttachment | CREATE_COMPLETE | None |
| 2019-10-25T10:17:32.512Z| AppSecurityGroup | AWS::EC2::SecurityGroup | CREATE_COMPLETE | None |
| 2019-10-25T10:17:31.837Z| AppSecurityGroup | AWS::EC2::SecurityGroup | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:29.785Z| AppRoute | AWS::EC2::Route | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:29.338Z| AppRoute | AWS::EC2::Route | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:27.918Z| AppRouteTable | AWS::EC2::RouteTable | CREATE_COMPLETE | None |
| 2019-10-25T10:17:27.784Z| AppSubnet | AWS::EC2::Subnet | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:27.404Z| AppSubnet | AWS::EC2::Subnet | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:27.373Z| AppRouteTable | AWS::EC2::RouteTable | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:27.357Z| AppVPCGatewayAttachment | AWS::EC2::VPCGatewayAttachment | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:27.208Z| AppSecurityGroup | AWS::EC2::SecurityGroup | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:27.131Z| AppRouteTable | AWS::EC2::RouteTable | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:27.050Z| AppVPCGatewayAttachment | AWS::EC2::VPCGatewayAttachment | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:25.634Z| AppVPC | AWS::EC2::VPC | CREATE_COMPLETE | None |
| 2019-10-25T10:17:24.868Z| AppInternetGateway | AWS::EC2::InternetGateway | CREATE_COMPLETE | None |
| 2019-10-25T10:17:23.193Z| AppInstanceProfile | AWS::IAM::InstanceProfile | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:22.925Z| AppInstanceProfile | AWS::IAM::InstanceProfile | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:21.157Z| AppInstanceRole | AWS::IAM::Role | CREATE_COMPLETE | None |
| 2019-10-25T10:17:09.723Z| AppInstanceRole | AWS::IAM::Role | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:09.584Z| AppVPC | AWS::EC2::VPC | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:09.378Z| AppInstanceRole | AWS::IAM::Role | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:09.248Z| AppInternetGateway | AWS::EC2::InternetGateway | CREATE_IN_PROGRESS | Resource creation Initiated |
| 2019-10-25T10:17:09.242Z| AppVPC | AWS::EC2::VPC | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:08.991Z| AppInternetGateway | AWS::EC2::InternetGateway | CREATE_IN_PROGRESS | None |
| 2019-10-25T10:17:06.414Z| jhw-hello-world | AWS::CloudFormation::Stack | CREATE_IN_PROGRESS | User Initiated |
| 2019-10-25T10:17:01.149Z| jhw-hello-world | AWS::CloudFormation::Stack | REVIEW_IN_PROGRESS | User Initiated |
+--------------------------+---------------------------------+-----------------------------------------+---------------------+-------------------------------+
justin@justin-XPS-13-9360:~/work$ ./describe_resources.sh
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| DescribeStackResources |
+--------------------------+---------------------------------+----------------------------------------------------+----------------------------------------+-------------------+
| 1.Timestamp | 2.LogicalId | 3.PhysicalId | 4.Type | 5.Status |
+--------------------------+---------------------------------+----------------------------------------------------+----------------------------------------+-------------------+
| 2019-10-25T10:19:41.478Z| AppEC2Instance | i-09d7b0d705b5d1fc6 | AWS::EC2::Instance | CREATE_COMPLETE |
| 2019-10-25T10:19:23.622Z| AppInstanceProfile | jhw-hello-world-AppInstanceProfile-1FN5IDFS1R8IC | AWS::IAM::InstanceProfile | CREATE_COMPLETE |
| 2019-10-25T10:17:21.157Z| AppInstanceRole | jhw-hello-world-AppInstanceRole-KY3DH8G7ZSKO | AWS::IAM::Role | CREATE_COMPLETE |
| 2019-10-25T10:17:24.868Z| AppInternetGateway | igw-0f36653c3f0ab2980 | AWS::EC2::InternetGateway | CREATE_COMPLETE |
| 2019-10-25T10:17:45.063Z| AppRoute | jhw-h-AppRo-1QJUEK3VNVNYM | AWS::EC2::Route | CREATE_COMPLETE |
| 2019-10-25T10:17:27.918Z| AppRouteTable | rtb-08ca99d5b7fcb73c6 | AWS::EC2::RouteTable | CREATE_COMPLETE |
| 2019-10-25T10:17:32.512Z| AppSecurityGroup | sg-0399c4eb233427ecd | AWS::EC2::SecurityGroup | CREATE_COMPLETE |
| 2019-10-25T10:17:43.418Z| AppSubnet | subnet-008d8c07200525759 | AWS::EC2::Subnet | CREATE_COMPLETE |
| 2019-10-25T10:18:00.605Z| AppSubnetRouteTableAssociation | rtbassoc-09927e545262a0791 | AWS::EC2::SubnetRouteTableAssociation | CREATE_COMPLETE |
| 2019-10-25T10:17:25.634Z| AppVPC | vpc-0ba045e3504dad737 | AWS::EC2::VPC | CREATE_COMPLETE |
| 2019-10-25T10:17:42.684Z| AppVPCGatewayAttachment | jhw-h-AppVP-8JP47UGN0I5N | AWS::EC2::VPCGatewayAttachment | CREATE_COMPLETE |
+--------------------------+---------------------------------+----------------------------------------------------+----------------------------------------+-------------------+
justin@justin-XPS-13-9360:~/work$ ./describe_outputs.sh
------------------------------------------------------------------------------------------------
| DescribeStacks |
+------------------------+---------------+-----------------------------------------------------+
| Description | OutputKey | OutputValue |
+------------------------+---------------+-----------------------------------------------------+
| EC2 instance id | MyInstanceId | i-09d7b0d705b5d1fc6 |
| EC2 public DNS name | MyDNSName | ec2-18-203-234-19.eu-west-1.compute.amazonaws.com |
| EC2 public IP address | MyIPAddress | 18.203.234.19 |
+------------------------+---------------+-----------------------------------------------------+
justin@justin-XPS-13-9360:~/work$ ./dump_ec2_logs.sh i-09d7b0d705b5d1fc6
justin@justin-XPS-13-9360:~/work$ grep -r Agent ec2-log.txt
Starting LSB: AWS CodeDeploy Host Agent...
[ OK ] Started LSB: AWS CodeDeploy Host Agent.
[ 40.549252] cloud-init[1808]: ● codedeploy-agent.service - LSB: AWS CodeDeploy Host Agentci-info: ++++++++++Authorized keys from /home/ubuntu/.ssh/authorized_keys for user ubuntu++++++++++
[ 40.704695] cloud-init[1808]: Oct 26 11:13:11 ip-172-31-0-134 systemd[1]: Starting LSB: AWS CodeDeploy Host Agent...
[ 40.728227] cloud-init[1808]: Oct 26 11:13:11 ip-172-31-0-134 systemd[1]: Started LSB: AWS CodeDeploy Host Agent.
[ 40.740852] cloud-init[1808]: + echo 'CodeDeploy Agent installed and started :-)'
[ 40.752864] cloud-init[1808]: CodeDeploy Agent installed and started :-)
justin@justin-XPS-13-9360:~/work$ ./delete_stack.sh
justin@justin-XPS-13-9360:~/work$ ./describe_stacks.sh
--------------------------------------------------------------------------------
| DescribeStacks |
+-----------------------------------------------------------+------------------+
| 1.Name | 2.Status |
+-----------------------------------------------------------+------------------+
| #{an_existing_stack} | UPDATE_COMPLETE |
+-----------------------------------------------------------+------------------+
justin@justin-XPS-13-9360:~/work$
If UserData
doesn't work, you need to ssh into the machine and see what the problem is, possibly by inspecting the logs -
ssh -i #{path/to/private/key} [email protected]
Remember that different AMIs have different root user names - Ubuntu uses ubuntu
(see above) but the default AWS Linux uses ec2-user
justin@justin-XPS-13-9360:~/work$ ./describe_keypairs.sh
----------------------------------------------------------------------------------------------------
| DescribeKeyPairs |
+--------------------------------------------------------------------------------------------------+
|| KeyPairs ||
|+--------------------------------------------------+-------------------+-------------------------+|
|| KeyFingerprint | KeyName | KeyPairId ||
|+--------------------------------------------------+-------------------+-------------------------+|
|| XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | jhw-keypair-x240 | key-XXXXXXXXXXXXXXXXX ||
|+--------------------------------------------------+-------------------+-------------------------+|
justin@justin-XPS-13-9360:~/work$ ./create_keypair.sh hello-ec2
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -----BEGIN RSA PRIVATE KEY-----
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-----END RSA PRIVATE KEY----- hello-ec2 key-084d4591601369262
- copy the stuff inside the
---(BEGIN)|(END) RSA PRIVATE KEY---
declarations into a local file - you will need this for ssh`ing into your machine later :-)
justin@justin-XPS-13-9360:~/work$ ./describe_keypairs.sh
---------------------------------------------------------------------------------------------------------
| DescribeKeyPairs |
+-------------------------------------------------------------------------------------------------------+
|| KeyPairs ||
|+--------------------------------------------------------------+------------+-------------------------+|
|| KeyFingerprint | KeyName | KeyPairId ||
|+--------------------------------------------------------------+------------+-------------------------+|
|| XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | hello-ec2 | key-XXXXXXXXXXXXXXXXX ||
|+--------------------------------------------------------------+------------+-------------------------+|
|| KeyPairs ||
|+-----------------------------------------------------+--------------------+--------------------------+|
|| KeyFingerprint | KeyName | KeyPairId ||
|+-----------------------------------------------------+--------------------+--------------------------+|
|| XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | jhw-keypair-x240 | key-XXXXXXXXX ||
|+-----------------------------------------------------+--------------------+--------------------------+|