Skip to content

Instantly share code, notes, and snippets.

@jhw
Last active April 18, 2020 08:01
Show Gist options
  • Save jhw/9c595edb615381780a2ba76791722fc3 to your computer and use it in GitHub Desktop.
Save jhw/9c595edb615381780a2ba76791722fc3 to your computer and use it in GitHub Desktop.
Hello World EC2
bin
include
lib
local
share
*.pyc
app.props
ec2-log.txt
*.pem
tmp/

dependencies

  • create an app.props file as follows -
AppName=jhw-hello-world

running the example

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$ 

debugging

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

some additional keypair stuff

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   ||
|+-----------------------------------------------------+--------------------+--------------------------+|
AppName=jhw-hello-world
S3DeployBucket=wol-deployments
#!/bin/bash
if [ -d /home/ubuntu/app ]; then
cd /home/ubuntu/app && ./hello_erlang_release/bin/hello_erlang_release-1 start
fi
#!/bin/bash
if [ -d /home/ubuntu/app ]; then
cd /home/ubuntu/app && ./hello_erlang_release/bin/hello_erlang_release-1 stop
fi
---
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/app
hooks:
ApplicationStop:
- location: application_stop.sh
timeout: 1200
runas: root
BeforeInstall:
- location: before_install.sh
timeout: 1200
runas: root
ApplicationStart:
- location: application_start.sh
timeout: 1200
runas: root
import datetime, re
def is_int(text):
return re.search("^\\-?\\d+$", text)!=None
def is_float(text):
return re.search("^\\-?\\d+\\.\\d+$", text)!=None
# NB currently permits 0.00000-9.99999 only
def is_float_minmax(text):
return re.search("^\\d+\\.\\d+\\-\\d+\\.\\d+$", text)!=None
def is_date(text):
return re.search("^\\d{4}\\-\\d{2}\\-\\d{2}$", text)!=None
def is_bool(text):
return re.search("^(true)|(false)$", text, re.I)!=None
def is_enum(text):
return True
def is_str(text):
return True
def parse_int(text):
return int(text)
def parse_float(text):
return float(text)
def parse_float_minmax(text):
return tuple([float(tok)
for tok in text.split("-")])
def parse_date(text):
# return datetime.datetime.strptime(text, "%Y-%m-%d").date()
return text
def parse_bool(text):
# return bool(text.lower().capitalize())
return text.lower() not in ["0", "false"]
def parse_enum(text):
return text
def parse_str(text):
return text
def validate_int(value, item):
if ("max" in item and
value > item["max"]):
raise RuntimeError("Value exceeeds maximum")
elif ("min" in item and
value < item["min"]):
raise RuntimeError("Value exceeeds minimum")
def validate_float(value, item):
validate_int(value, item)
def validate_float_minmax(value, item):
pass
def validate_date(value, item):
pass
def validate_bool(value, item):
pass
def validate_enum(value, item):
if value not in item["options"]:
raise RuntimeError("Value is not a valid option")
def validate_str(value, item):
pass
def argsparse(args, config):
if len(args)!=len(config):
raise RuntimeError("Please enter %s" % ", ".join((item["name"]
for item in config)))
kwargs={}
for text, item in zip(args, config):
matcher=eval("is_%s" % item["type"])
if not matcher(text):
raise RuntimeError("%s type is invalid" % item["name"])
parser=eval("parse_%s" % item["type"])
value=parser(text)
validator=eval("validate_%s" % item["type"])
validator(value, item)
kwargs[item["name"]]=value
return kwargs
#!/bin/bash
if [ -d /home/ubuntu/app ]; then
rm -rf /home/ubuntu/app
fi
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
AppName:
Type: String
Resources:
CodeDeployApp:
Properties:
ApplicationName: !Ref AppName
Type: AWS::CodeDeploy::Application
CodeDeployGroup:
Properties:
ApplicationName:
Ref: CodeDeployApp
DeploymentConfigName: CodeDeployDefault.AllAtOnce
DeploymentGroupName: !Ref AppName
Ec2TagFilters:
- Key: Name
Type: KEY_AND_VALUE
Value: !Ref AppName
ServiceRoleArn: !GetAtt CodeDeployRole.Arn
Type: AWS::CodeDeploy::DeploymentGroup
CodeDeployRole:
Properties:
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- codedeploy.amazonaws.com
Version: '2012-10-17'
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole
Path: /
Type: AWS::IAM::Role
#!/usr/bin/env bash
if [ -z $1 ]
then
echo "Please enter keypair name"
exit 1
fi
aws ec2 create-key-pair --key-name $1 --output text
#!/usr/bin/env bash
if [ -z $1 ]
then
echo "Please enter keypair name"
exit 1
fi
aws ec2 delete-key-pair --key-name $1 --output text
#!/usr/bin/env bash
. app.props
aws cloudformation delete-stack --stack-name $AppName
#!/usr/bin/env bash
. app.props
if [ -z $1 ]
then
echo "Please enter EC2 KeyName"
exit 1
fi
aws s3 cp ec2.yaml s3://$S3DeployBucket/$AppName/ec2.yaml
aws s3 cp networking.yaml s3://$S3DeployBucket/$AppName/networking.yaml
aws s3 cp iam.yaml s3://$S3DeployBucket/$AppName/iam.yaml
aws s3 cp codedeploy.yaml s3://$S3DeployBucket/$AppName/codedeploy.yaml
aws cloudformation deploy --stack-name $AppName --template-file stack.yaml --parameter-overrides AppName=$AppName S3DeployBucket=$S3DeployBucket KeyName=$1 --capabilities CAPABILITY_NAMED_IAM
#!/usr/bin/env bash
. app.props
aws cloudformation describe-stack-events --stack-name $AppName --query "StackEvents[].{\"1.Timestamp\":Timestamp,\"2.Id\":LogicalResourceId,\"3.Type\":ResourceType,\"4.Status\":ResourceStatus,\"5.Reason\":ResourceStatusReason}"
#!/usr/bin/env bash
aws ec2 describe-key-pairs
#!/usr/bin/env bash
. app.props
aws cloudformation describe-stacks --stack-name $AppName --query 'Stacks[0].Outputs' --output table
#!/usr/bin/env bash
. app.props
aws cloudformation describe-stack-resources --stack-name $AppName --query "StackResources[].{\"1.Timestamp\":Timestamp,\"2.LogicalId\":LogicalResourceId,\"3.PhysicalId\":PhysicalResourceId,\"4.Type\":ResourceType,\"5.Status\":ResourceStatus}"
#!/usr/bin/env bash
aws cloudformation describe-stacks --query "Stacks[].{\"1.Name\":StackName,\"2.Status\":StackStatus}"
#!/usr/bin/env bash
if [ -z $1 ]
then
echo "Please enter EC2 instance id [try ./describe_outputs.sh]"
exit 1
fi
aws ec2 get-console-output --instance-id $1 > ec2-log.txt
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
AppName:
Type: String
InstanceType:
Type: String
InstanceRole:
Type: String
ImageId:
Type: String
SecurityGroup:
Type: String
Subnet:
Type: String
KeyName:
Type: String
Outputs:
PublicDnsName:
Value: !GetAtt Instance.PublicDnsName
Description: "Public Dns Name"
PublicIp:
Value: !GetAtt Instance.PublicIp
Description: "Public Ip"
InstanceId:
Value: !Ref Instance
Description: "Instance Id"
Resources:
Instance:
CreationPolicy:
ResourceSignal:
Count: '1'
Timeout: PT15M
Properties:
IamInstanceProfile: !Ref InstanceProfile
ImageId: !Ref ImageId
InstanceType: !Ref InstanceType
KeyName: !Ref KeyName
SecurityGroupIds:
- !Ref SecurityGroup
SubnetId: !Ref Subnet
Tags:
- Key: Name
Value: !Ref AppName
UserData:
Fn::Base64:
!Sub |
#!/bin/bash
echo "starting UserData script .."
apt-get update
apt-get install -y python
apt-get install -y python-pip
apt-get install -y ruby
apt-get install -y wget
cd /home/ubuntu
echo "downloading/installing CodeDeploy Agent .."
wget https://aws-codedeploy-${AWS::Region}.s3.amazonaws.com/latest/install
chmod +x ./install
./install auto
service codedeploy-agent start
service codedeploy-agent status
echo "CodeDeploy Agent installed and started :-)"
echo "downloading/installing CloudWatch Logs Agent .."
# https://aws.amazon.com/blogs/devops/view-aws-codedeploy-logs-in-amazon-cloudwatch-console/
wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
wget https://aws-codedeploy-${AWS::Region}.s3.amazonaws.com/cloudwatch/codedeploy_logs.conf
chmod +x ./awslogs-agent-setup.py
python awslogs-agent-setup.py -n -r ${AWS::Region} -c s3://aws-codedeploy-${AWS::Region}/cloudwatch/awslogs.conf
mkdir -p /var/awslogs/etc/config
cp codedeploy_logs.conf /var/awslogs/etc/config/
service awslogs start
service awslogs status
echo "CloudWatch Logs Agent installed and started :-)"
echo "downloading/installing aws-cfn-bootstrap"
pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
ln -s /root/aws-cfn-bootstrap-latest/init/ubuntu/cfn-hup /etc/init.d/cfn-hup
echo "Sending CREATE_COMPLETE signal .."
cfn-signal -e $? --stack ${AWS::StackName} --resource Instance --region ${AWS::Region}
Type: AWS::EC2::Instance
InstanceProfile:
Properties:
Path: /
Roles:
- !Ref InstanceRole
Type: AWS::IAM::InstanceProfile
  • virtualenv -p /usr/bin/python3.6 .
  • . bin/activate
  • pip install -U -r requirements.txt
  • {...}
  • deactivate

cheatsheet 2/4/20

signal 28/3/20

https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz

Uses the Python easy-install tools. To complete the installation for Ubuntu, you must create a symlink:

ln -s /root/aws-cfn-bootstrap-latest/init/ubuntu/cfn-hup /etc/init.d/cfn-hup

short

  • extend scripts to query nested stacks

medium

thoughts

  • userdata reloading ?

done

  • script to create deployable and push to s3
  • script to deploy app using codedeploy
  • check app started
  • added codedeploy artifacts
  • test and copy erlang release
    • check port 80 in config/sys.config
  • test current script works
  • refactor ec2 blog post
  • add back codedeploy
  • move more ec2 params into master
  • ensure all outputs suffixed by id etc
  • re- test ec2
  • test new templates
  • can't seem to output instanceid
  • codedeploy
This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment