Skip to content

Instantly share code, notes, and snippets.

@antklim
antklim / ecs-stack-part.yml
Created February 15, 2018 21:30
The part of ECS CloudFormation template
ECSLaunchConfiguration:
DependsOn: ECSCluster
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
...
UserData:
"Fn::Base64": !Sub |
#!/bin/bash
export HTTP_PROXY=${ProxyHost}:${ProxyPort}
Parameters:
Environment:
Description: An environment name that will be prefixed to resource names
Type: String
Namespace:
Description: An infrastructure namespace that will be prefixed to resource names
Type: String
Default: simple-api
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
Tags:
- Key: Name
Value: !Sub ${Namespace}-${Environment}-VPC
InternetGateway:
Type: AWS::EC2::InternetGateway
Mappings:
AWSRegionToAMI:
ap-southeast-2:
AMI: ami-942dd1f6
PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
CidrBlock: !Ref PublicSubnet1CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub ${Namespace}-${Environment}-public-subnet-az1
NatGateway1EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
NatGateway2EIP:
Type: AWS::EC2::EIP
DependsOn: InternetGatewayAttachment
Properties:
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${Namespace}-${Environment}-public-routes
PrivateRouteTable1:
Type: AWS::EC2::RouteTable
LoadBalancerSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Access to load balancer that sits in front of EC2 hosts
VpcId: !Ref VPC
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
IpProtocol: -1
Tags:
- Key: Name
LoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !Sub ${Namespace}-${Environment}-ALB
Subnets:
- !Ref PublicSubnet1
- !Ref PublicSubnet2
SecurityGroups:
- !Ref LoadBalancerSecurityGroup
Tags:
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
LaunchConfigurationName: !Ref LaunchConfiguration
MinSize: 4
MaxSize: 4
DesiredCapacity: 4