Created
September 22, 2022 13:48
-
-
Save nmagee/58da4c4d7124330f8d423b41616f8d9c to your computer and use it in GitHub Desktop.
CF template to create EC2 instance with EIP attached.
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: >- | |
AWS CloudFormation Sample Template EIP_With_Association: This template | |
creates an Amazon EC2 instance and an Elastic IP Address. You will be | |
billed for the AWS resources used if you create a stack from this template. | |
Parameters: | |
InstanceType: | |
Description: Web Server EC2 instance type | |
Type: String | |
Default: t2.small | |
AllowedValues: | |
- t1.micro | |
- t2.nano | |
- t2.micro | |
- t2.small | |
- t2.medium | |
- t2.large | |
ConstraintDescription: must be a valid EC2 instance type. | |
KeyName: | |
Description: Name of an existing EC2 KeyPair to enable SSH access to the instances | |
Type: 'AWS::EC2::KeyPair::KeyName' | |
ConstraintDescription: must be the name of an existing EC2 KeyPair. | |
SSHLocation: | |
Description: The IP address range that can be used to SSH to the EC2 instances | |
Type: String | |
MinLength: '9' | |
MaxLength: '18' | |
Default: 0.0.0.0/0 | |
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' | |
ConstraintDescription: Must be a valid IP CIDR range of the form x.x.x.x/x. | |
Mappings: | |
AWSInstanceType2Arch: | |
t1.micro: | |
Arch: HVM64 | |
t2.nano: | |
Arch: HVM64 | |
t2.micro: | |
Arch: HVM64 | |
t2.small: | |
Arch: HVM64 | |
t2.medium: | |
Arch: HVM64 | |
t2.large: | |
Arch: HVM64 | |
AWSInstanceType2NATArch: | |
t1.micro: | |
Arch: NATHVM64 | |
t2.nano: | |
Arch: NATHVM64 | |
t2.micro: | |
Arch: NATHVM64 | |
t2.small: | |
Arch: NATHVM64 | |
t2.medium: | |
Arch: NATHVM64 | |
t2.large: | |
Arch: NATHVM64 | |
AWSRegionArch2AMI: | |
us-east-1: | |
HVM64: ami-032930428bf1abbff | |
HVMG2: ami-0aeb704d503081ea6 | |
us-east-2: | |
HVM64: ami-027cab9a7bf0155df | |
HVMG2: NOT_SUPPORTED | |
us-west-1: | |
HVM64: ami-088c153f74339f34c | |
HVMG2: ami-0a7fc72dc0e51aa77 | |
us-west-2: | |
HVM64: ami-01fee56b22f308154 | |
HVMG2: ami-0fe84a5b4563d8f27 | |
Resources: | |
EC2Instance: | |
Type: 'AWS::EC2::Instance' | |
Properties: | |
UserData: !Base64 | |
'Fn::Join': | |
- '' | |
- - IPAddress= | |
- !Ref IPAddress | |
InstanceType: !Ref InstanceType | |
SecurityGroups: | |
- !Ref InstanceSecurityGroup | |
KeyName: !Ref KeyName | |
ImageId: !FindInMap | |
- AWSRegionArch2AMI | |
- !Ref 'AWS::Region' | |
- !FindInMap | |
- AWSInstanceType2Arch | |
- !Ref InstanceType | |
- Arch | |
InstanceSecurityGroup: | |
Type: 'AWS::EC2::SecurityGroup' | |
Properties: | |
GroupDescription: Enable SSH access | |
SecurityGroupIngress: | |
- IpProtocol: tcp | |
FromPort: '22' | |
ToPort: '22' | |
CidrIp: !Ref SSHLocation | |
IPAddress: | |
Type: 'AWS::EC2::EIP' | |
IPAssoc: | |
Type: 'AWS::EC2::EIPAssociation' | |
Properties: | |
InstanceId: !Ref EC2Instance | |
EIP: !Ref IPAddress | |
Outputs: | |
InstanceId: | |
Description: InstanceId of the newly created EC2 instance | |
Value: !Ref EC2Instance | |
InstanceIPAddress: | |
Description: IP address of the newly created EC2 instance | |
Value: !Ref IPAddress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Launch this here