Skip to content

Instantly share code, notes, and snippets.

@sudheerchamarthi
Last active May 26, 2022 02:46
Show Gist options
  • Save sudheerchamarthi/ff3990c9d38b22502722d7cfa0817ce5 to your computer and use it in GitHub Desktop.
Save sudheerchamarthi/ff3990c9d38b22502722d7cfa0817ce5 to your computer and use it in GitHub Desktop.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'I am creating 2 s3 buckets and an EC2 instance'
Mappings:
RegionAMI:
us-east-1:
al2: ami-0022f774911c1d690
ubuntu: ami-09d56f8956ab235b3
redhat: ami-0f095f89ae15be883
us-east-2:
al2: ami-12345678987654
ubuntu: ami-987654345678987
redhat: ami-87654345678
us-west-2:
al2: ami-987654345678
ubuntu: ami-987654345678
redhat: ami-9876543we567t
Parameters:
s3bucketname1:
Type: String
Default: mys3bucket-9876545679
Description: Enter bucket name of your choice
s3bucketname2:
Type: String
Default: mys3bucket-9876545679876
Description: Enter bucket name of your choice
# imageid:
# Type: String
# Default: ami-0022f774911c1d690
# Description: Enter AMI id of your choice
key:
Type: AWS::EC2::KeyPair::KeyName
Default: efstest
Description: Select key KeyPair of your choice
owner:
Type: String
Default: sudheer
AllowedValues:
- sudheer
- abc
- def
Description: Select the owner
InstanceType:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- t2.medium
- m1.large
Description: Enter t2.micro, m1.small, or m1.large. Default is t2.micro.
OsType:
Type: String
Default: al2
AllowedValues:
- al2
- ubuntu
- redhat
Description: Choose OS type. Default is al2
Resources:
S3Bucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Properties:
#This bucket is used for storing logs
BucketName:
Ref: s3bucketname1
Tags:
- Key: "owner"
Value:
Ref: owner
S3Bucket2:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
#This bucket is used for storing logs
BucketName:
Ref: s3bucketname2
Tags:
- Key: "owner"
Value:
Ref: owner
- Key: "S3Name"
Value:
Ref: S3Bucket
web:
Type: AWS::EC2::Instance
Properties:
ImageId: !FindInMap [RegionAMI, !Ref "AWS::Region", !Ref OsType]
KeyName:
Ref: key
InstanceType:
Ref: InstanceType
BlockDeviceMappings:
- DeviceName: "/dev/sdm"
Ebs:
VolumeType: "io1"
Iops: "200"
DeleteOnTermination: "false"
VolumeSize: "20"
- DeviceName: "/dev/sdk"
NoDevice: {}
Tags:
- Key: "owner"
Value:
Ref: owner
- Key: "Name"
Value: "web"
- Key: "S3Name"
Value:
Ref: S3Bucket
Outputs:
publicip:
Description: PublicIP of my instance
Value: !GetAtt web.PublicIp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment