Last active
May 23, 2019 04:43
-
-
Save MatthewJDavis/edcaa9d2c362464b7e5f7bced50df1b1 to your computer and use it in GitHub Desktop.
AWS cloudformation YAML template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Description: Create a basic Amazon Linux Server with security group in existing VPC and subnet | |
Parameters: | |
KeyName: | |
Description: Key Pair name | |
Type: 'AWS::EC2::KeyPair::KeyName' | |
Default: keyPair | |
VPC: | |
Description: Select a VPC | |
Type: 'AWS::EC2::VPC::Id' | |
Subnet: | |
Description: Select a subnet from the VPC | |
Type: 'AWS::EC2::Subnet::Id' | |
InstanceType: | |
Description: Select one of the instance types | |
Type: String | |
Default: t2.micro | |
AllowedValues: | |
- t2.micro | |
- t2.small | |
- t2.medium | |
Name: | |
Description: The name of the instance | |
Type: String | |
# EC2 AMIs are mapped for Amazon linux to the following regions. This will pick the correct AMI for the region | |
Mappings: | |
EC2RegionMap: | |
ap-northeast-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-cbf90ecb | |
ap-southeast-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-68d8e93a | |
ap-southeast-2: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-fd9cecc7 | |
eu-central-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-a8221fb5 | |
eu-west-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-a10897d6 | |
sa-east-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-b52890a8 | |
us-east-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-1ecae776 | |
us-west-1: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-d114f295 | |
us-west-2: | |
AmazonLinuxAMIHVMEBSBacked64bit: ami-e7527ed7 | |
Resources: | |
# create security group to allow ssh | |
SecurityGroup: | |
Type: 'AWS::EC2::SecurityGroup' | |
Properties: | |
GroupDescription: basic-amazon-linux-sg | |
VpcId: !Ref VPC | |
SecurityGroupIngress: | |
- CidrIp: 0.0.0.0/0 | |
FromPort: 22 | |
IpProtocol: tcp | |
ToPort: 22 | |
Server: | |
Type: 'AWS::EC2::Instance' | |
Properties: | |
ImageId: !FindInMap | |
- EC2RegionMap | |
- !Ref 'AWS::Region' | |
- AmazonLinuxAMIHVMEBSBacked64bit | |
InstanceType: !Ref InstanceType | |
KeyName: !Ref KeyName | |
SecurityGroupIds: | |
- !Ref SecurityGroup | |
SubnetId: !Ref Subnet | |
Tags: | |
- | |
Key: Name | |
Value: !Ref Name | |
Outputs: | |
PublicName: | |
Value: !GetAtt | |
- Server | |
- PublicDnsName | |
Description: Public name (connect via SSH as user ec2-user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment