Skip to content

Instantly share code, notes, and snippets.

@midN
Last active December 30, 2018 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midN/3d8edca2c8ac18be87158a4f5ab9e49a to your computer and use it in GitHub Desktop.
Save midN/3d8edca2c8ac18be87158a4f5ab9e49a to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
vpcId:
Type: AWS::EC2::VPC::Id
subnet:
Type: AWS::EC2::Subnet::Id
zone:
Type: AWS::Route53::HostedZone::Id
Resources:
lb:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Subnets:
- !Ref subnet
tg:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Port: 80
Protocol: HTTP
VpcId: !Ref vpcId
http:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref lb
DefaultActions:
- Type: forward
TargetGroupArn: !Ref tg
Port: 80
Protocol: HTTP
td:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Name: nginx
Image: nginx:latest
PortMappings:
- ContainerPort: 80
HostPort: 80
cluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: cluster
ecs:
Type: AWS::ECS::Service
Properties:
Cluster: !Ref cluster
DesiredCount: 1
TaskDefinition: !Ref td
ServiceName: service
LoadBalancers:
- ContainerName: nginx
ContainerPort: 80
LoadBalancerName: !Ref lb
lc:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
# us-east-1 ecs-optimized: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html
ImageId: ami-045f1b3f87ed83659
InstanceType: t3.nano
UserData:
!Base64
"Fn::Sub": |
#!/bin/bash
echo ECS_CLUSTER=cluster >> /etc/ecs/ecs.config
ag:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
DesiredCapacity: 1
LaunchConfigurationName: !Ref lc
DependsOn:
- cluster
cname:
Type: AWS::Route53::RecordSet
Properties:
Name: yourapp
Type: "CNAME"
HostedZoneId: !Ref zone
ResourceRecords:
- !Ref lb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment