Created
June 6, 2017 19:56
-
-
Save MatthewJDavis/6bc2803209ed334bc3a5d2388476e66d to your computer and use it in GitHub Desktop.
2 EC2 Insances with Elastic IP addresses
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 | |
NameInstance1: | |
Description: The name of the instance 1 | |
Type: String | |
NameInstance2: | |
Description: The name of the instance 2 | |
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 1 | |
Server1: | |
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 NameInstance1 | |
EIP1: | |
Type: AWS::EC2::EIP | |
Properties: | |
InstanceId: !Ref Server1 | |
#Server 2 | |
Server2: | |
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 NameInstance2 | |
EIP2: | |
Type: AWS::EC2::EIP | |
Properties: | |
InstanceId: !Ref Server2 | |
Outputs: | |
#Output for server 1 | |
PublicName: | |
Value: !GetAtt | |
- Server1 | |
- PublicDnsName | |
Description: Public name (connect via SSH as user ec2-user) | |
PublicIP: | |
Value: !GetAtt | |
- Server1 | |
- PublicIp | |
#Output for server 2 | |
PublicName: | |
Value: !GetAtt | |
- Server2 | |
- PublicDnsName | |
Description: Public name (connect via SSH as user ec2-user) | |
PublicIP: | |
Value: !GetAtt | |
- Server2 | |
- PublicIp | |
Description: Public IP for server 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment