Skip to content

Instantly share code, notes, and snippets.

@anneakin
Last active May 23, 2020 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anneakin/cde50d82f141d5fa56e9994e57c494d6 to your computer and use it in GitHub Desktop.
Save anneakin/cde50d82f141d5fa56e9994e57c494d6 to your computer and use it in GitHub Desktop.
AWS CloudFormation Resources
Resources:
UserS3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Join [ '-', [ !Ref Username, 's3-bucket' ] ]
EC2IamRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Join [ '-', [ !Ref Username, 'ec2-iam-role' ] ]
AssumeRolePolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EC2IamPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: !Join [ '-', [ !Ref Username, 'ec2-iam-policy' ] ]
Roles:
-
!Ref EC2IamRole
PolicyDocument: {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EC2IamInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
InstanceProfileName: !Join [ '-', [ !Ref Username, 'ec2-iam-profile' ] ]
Roles:
-
!Ref EC2IamRole
UserEc2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
IamInstanceProfile: !Ref EC2IamInstanceProfile
ImageId: ami-0a887e401f7654935
KeyName: !Ref UserKey
SubnetId: !Ref Subnet
Tags:
-
Key: Name
Value: !Join [ '-', [ !Ref Username, 'ec2-instance' ] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment