-
-
Save jarrodmedrano/3df26d7af65a9ba368fb3aaa92497377 to your computer and use it in GitHub Desktop.
An example CloudFormation template for deployment of a container to ECS.
This file contains hidden or 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" | |
Parameters: | |
SubnetID: | |
Type: String | |
Resources: | |
Cluster: | |
Type: AWS::ECS::Cluster | |
Properties: | |
ClusterName: deployment-example-cluster | |
LogGroup: | |
Type: AWS::Logs::LogGroup | |
Properties: | |
LogGroupName: deployment-example-log-group | |
ExecutionRole: | |
Type: AWS::IAM::Role | |
Properties: | |
RoleName: deployment-example-role | |
AssumeRolePolicyDocument: | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: ecs-tasks.amazonaws.com | |
Action: sts:AssumeRole | |
ManagedPolicyArns: | |
- arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy | |
ContainerSecurityGroup: | |
Type: AWS::EC2::SecurityGroup | |
Properties: | |
GroupName: ContainerSecurityGroup | |
GroupDescription: Security group for NGINX container | |
SecurityGroupIngress: | |
- IpProtocol: tcp | |
FromPort: 80 | |
ToPort: 80 | |
CidrIp: 0.0.0.0/0 | |
TaskDefinition: | |
Type: AWS::ECS::TaskDefinition | |
Properties: | |
Family: deployment-example-task | |
Cpu: 256 | |
Memory: 512 | |
NetworkMode: awsvpc | |
ExecutionRoleArn: !Ref ExecutionRole | |
ContainerDefinitions: | |
- Name: deployment-example-container | |
Image: nginx:1.17.7 | |
PortMappings: | |
- ContainerPort: 80 | |
LogConfiguration: | |
LogDriver: awslogs | |
Options: | |
awslogs-region: !Ref AWS::Region | |
awslogs-group: !Ref LogGroup | |
awslogs-stream-prefix: ecs | |
RequiresCompatibilities: | |
- EC2 | |
- FARGATE | |
Service: | |
Type: AWS::ECS::Service | |
Properties: | |
ServiceName: deployment-exmaple-service | |
Cluster: !Ref Cluster | |
TaskDefinition: !Ref TaskDefinition | |
DesiredCount: 1 | |
LaunchType: FARGATE | |
NetworkConfiguration: | |
AwsvpcConfiguration: | |
AssignPublicIp: ENABLED | |
Subnets: | |
- !Ref SubnetID | |
SecurityGroups: | |
- !GetAtt ContainerSecurityGroup.GroupId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment