Skip to content

Instantly share code, notes, and snippets.

@neverendingqs
Last active March 26, 2020 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neverendingqs/8e129356fe9774169df5bcb8742ee3f4 to your computer and use it in GitHub Desktop.
Save neverendingqs/8e129356fe9774169df5bcb8742ee3f4 to your computer and use it in GitHub Desktop.
AWS Notes
# aws --profile <profile> --region ca-central-1 cloudformation deploy --stack-name <stack-name> --capabilities CAPABILITY_IAM --template-file single-ec2.yaml --parameter-overrides "KeyName=<keyname>" "IamInstanceProfileRole=<arn>"
---
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
KeyName:
Type: AWS::EC2::KeyPair::KeyName
IamInstanceProfileRole:
Description: Expects an ARN
Type: String
ImageId:
Type: AWS::EC2::Image::Id
Default: ami-0bf54ac1b628cf143
InstanceType:
Type: String
Default: t2.medium
Resources:
Instance:
Type: AWS::EC2::Instance
Properties:
IamInstanceProfile:
Ref: InstanceProfile
InstanceType:
Ref: InstanceType
SecurityGroups:
- Ref: InstanceSecurityGroup
KeyName:
Ref: KeyName
ImageId:
Ref: ImageId
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- Ref: InstanceProfileRole
InstanceProfileRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Security group for EC2 instance
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
Outputs:
InstancePublicDns:
Value:
!GetAtt Instance.PublicDnsName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment