Skip to content

Instantly share code, notes, and snippets.

@anneakin
anneakin / aws_cfn_sandbox.yml
Last active May 22, 2020 21:02
AWS CloudFormation simple sandbox template
AWSTemplateFormatVersion: "2010-09-09"
Description: Template to demonstrate simple sandbox environment resources
Parameters:
Username:
Type: String
Description: User's identifier used to label resources created in template.
UserKey:
Type: AWS::EC2::KeyPair::KeyName
Description: Existing EC2 key-pair to SSH into the instance.
@anneakin
anneakin / aws_cfn_sandbox_version_description.yml
Created May 23, 2020 00:46
AWS Template Format Version & Description
AWSTemplateFormatVersion: "2010-09-09"
Description: Template to demonstrate simple sandbox environment resources
@anneakin
anneakin / aws_cfn_sandbox_parameters.yml
Created May 23, 2020 00:48
AWS CloudFormation Parameters
Parameters:
Username:
Type: String
Description: User's identifier used to label resources created in template.
UserKey:
Type: AWS::EC2::KeyPair::KeyName
Description: Existing EC2 key-pair to SSH into the instance.
Subnet:
Type: AWS::EC2::Subnet::Id
Description: Subnet for EC2 instance
@anneakin
anneakin / aws_cfn_sandbox_resources.yml
Last active May 23, 2020 01:12
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' ] ]
@anneakin
anneakin / aws_cfn_sandbox_outputs.yml
Created May 23, 2020 00:49
AWS CloudFormation Outputs
Outputs:
EC2PrivateIp:
Description: Private IP address of EC2 instance created in stack.
Value: !GetAtt UserEc2Instance.PrivateIp
EC2PublicIp:
Description: Public IP address of EC2 instance created in stack.
Value: !GetAtt UserEc2Instance.PublicIp
@anneakin
anneakin / aws_cfn_sandbox_policy.yml
Created May 23, 2020 01:07
Policy document for EC2 IAM role
PolicyName: DestinationBucketAccessPolicy
PolicyDocument:
Version: '2012–10–17'
Statement:
- Effect: Allow
Action:
- s3:ListBucket
- s3:DeleteObject
- s3:GetObject
- s3:PutObject
@anneakin
anneakin / aws_cfn_ec2_userdata.yml
Created May 23, 2020 01:11
EC2 Instance resource with User Data
UserEc2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
IamInstanceProfile: !Ref EC2IamInstanceProfile
ImageId: ami-0a887e401f7654935
KeyName: !Ref UserKey
SubnetId: !Ref Subnet
Tags:
-
@anneakin
anneakin / variables.tf
Created May 23, 2020 01:19
Terraform sandbox variables
variable "username" {}
variable "user_key" {}
variable "subnet_id" {}
@anneakin
anneakin / main.tf
Created May 23, 2020 01:20
Terraform resources for sandbox
provider "aws" {
profile = "default"
region = "us-east-1"
}
resource "aws_s3_bucket" "user_s3_bucket" {
bucket = "${var.username}-s3-bucket"
}
resource "aws_iam_role" "ec2_iam_role" {
@anneakin
anneakin / outputs.tf
Created May 23, 2020 01:22
Terraform sandbox outputs file
output "ec2_public_ip" {
value = "${aws_instance.user_ec2_instance.public_ip}"
}
output "ec2_private_ip" {
value = "${aws_instance.user_ec2_instance.private_ip}"
}