baked in cloud formation template
parent
c59ad06451
commit
fe99ed800f
|
|
@ -1,416 +0,0 @@
|
||||||
AWSTemplateFormatVersion: '2010-09-09'
|
|
||||||
Description: AWS Fargate cluster that can span public and private subnets. Supports
|
|
||||||
public facing load balancers, private internal load balancers, and
|
|
||||||
both internal and external service discovery namespaces.
|
|
||||||
Parameters:
|
|
||||||
EnvironmentName:
|
|
||||||
Type: String
|
|
||||||
Default: development
|
|
||||||
Description: "Your deployment environment: DEV, QA , PROD"
|
|
||||||
Version:
|
|
||||||
Type: String
|
|
||||||
Description: "hash of template"
|
|
||||||
|
|
||||||
# ContainerPort:
|
|
||||||
# Type: Number
|
|
||||||
# Default: 80
|
|
||||||
# Description: What port number the application inside the docker container is binding to
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Mappings:
|
|
||||||
# Hard values for the subnet masks. These masks define
|
|
||||||
# the range of internal IP addresses that can be assigned.
|
|
||||||
# The VPC can have all IP's from 10.0.0.0 to 10.0.255.255
|
|
||||||
# There are four subnets which cover the ranges:
|
|
||||||
#
|
|
||||||
# 10.0.0.0 - 10.0.0.255
|
|
||||||
# 10.0.1.0 - 10.0.1.255
|
|
||||||
# 10.0.2.0 - 10.0.2.255
|
|
||||||
# 10.0.3.0 - 10.0.3.255
|
|
||||||
|
|
||||||
SubnetConfig:
|
|
||||||
VPC:
|
|
||||||
CIDR: '10.0.0.0/16'
|
|
||||||
PublicOne:
|
|
||||||
CIDR: '10.0.0.0/24'
|
|
||||||
PublicTwo:
|
|
||||||
CIDR: '10.0.1.0/24'
|
|
||||||
|
|
||||||
Resources:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# VPC in which containers will be networked.
|
|
||||||
# It has two public subnets, and two private subnets.
|
|
||||||
# We distribute the subnets across the first two available subnets
|
|
||||||
# for the region, for high availability.
|
|
||||||
VPC:
|
|
||||||
Type: AWS::EC2::VPC
|
|
||||||
Properties:
|
|
||||||
EnableDnsSupport: true
|
|
||||||
EnableDnsHostnames: true
|
|
||||||
CidrBlock: !FindInMap ['SubnetConfig', 'VPC', 'CIDR']
|
|
||||||
|
|
||||||
EFSServerSecurityGroup:
|
|
||||||
Type: AWS::EC2::SecurityGroup
|
|
||||||
Properties:
|
|
||||||
GroupName: "efs-server-endpoints"
|
|
||||||
GroupDescription: Which client ip addrs are allowed to access EFS server
|
|
||||||
VpcId: !Ref 'VPC'
|
|
||||||
SecurityGroupIngress:
|
|
||||||
- IpProtocol: tcp
|
|
||||||
FromPort: 2049
|
|
||||||
ToPort: 2049
|
|
||||||
SourceSecurityGroupId: !Ref ContainerSecurityGroup
|
|
||||||
#CidrIp: !FindInMap ['SubnetConfig', 'VPC', 'CIDR']
|
|
||||||
# A security group for the containers we will run in Fargate.
|
|
||||||
# Rules are added to this security group based on what ingress you
|
|
||||||
# add for the cluster.
|
|
||||||
ContainerSecurityGroup:
|
|
||||||
Type: AWS::EC2::SecurityGroup
|
|
||||||
Properties:
|
|
||||||
GroupName: "task security group"
|
|
||||||
GroupDescription: Access to the Fargate containers
|
|
||||||
VpcId: !Ref 'VPC'
|
|
||||||
# SecurityGroupIngress:
|
|
||||||
# - IpProtocol: tcp
|
|
||||||
# FromPort: !Ref ContainerPort
|
|
||||||
# ToPort: !Ref ContainerPort
|
|
||||||
# CidrIp: 0.0.0.0/0
|
|
||||||
SecurityGroupEgress:
|
|
||||||
- IpProtocol: -1
|
|
||||||
FromPort: 2049
|
|
||||||
ToPort: 2049
|
|
||||||
CidrIp: "0.0.0.0/0"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Two public subnets, where containers can have public IP addresses
|
|
||||||
PublicSubnetOne:
|
|
||||||
Type: AWS::EC2::Subnet
|
|
||||||
Properties:
|
|
||||||
AvailabilityZone: !Select
|
|
||||||
- 0
|
|
||||||
- Fn::GetAZs: !Ref 'AWS::Region'
|
|
||||||
VpcId: !Ref 'VPC'
|
|
||||||
CidrBlock: !FindInMap ['SubnetConfig', 'PublicOne', 'CIDR']
|
|
||||||
# MapPublicIpOnLaunch: true
|
|
||||||
|
|
||||||
PublicSubnetTwo:
|
|
||||||
Type: AWS::EC2::Subnet
|
|
||||||
Properties:
|
|
||||||
AvailabilityZone: !Select
|
|
||||||
- 1
|
|
||||||
- Fn::GetAZs: !Ref 'AWS::Region'
|
|
||||||
VpcId: !Ref 'VPC'
|
|
||||||
CidrBlock: !FindInMap ['SubnetConfig', 'PublicTwo', 'CIDR']
|
|
||||||
# MapPublicIpOnLaunch: true
|
|
||||||
|
|
||||||
|
|
||||||
# Setup networking resources for the public subnets. Containers
|
|
||||||
# in the public subnets have public IP addresses and the routing table
|
|
||||||
# sends network traffic via the internet gateway.
|
|
||||||
InternetGateway:
|
|
||||||
Type: AWS::EC2::InternetGateway
|
|
||||||
GatewayAttachement:
|
|
||||||
Type: AWS::EC2::VPCGatewayAttachment
|
|
||||||
Properties:
|
|
||||||
VpcId: !Ref 'VPC'
|
|
||||||
InternetGatewayId: !Ref 'InternetGateway'
|
|
||||||
|
|
||||||
# Attaching a Internet Gateway to route table makes it public.
|
|
||||||
PublicRouteTable:
|
|
||||||
Type: AWS::EC2::RouteTable
|
|
||||||
Properties:
|
|
||||||
VpcId: !Ref 'VPC'
|
|
||||||
PublicRoute:
|
|
||||||
Type: AWS::EC2::Route
|
|
||||||
DependsOn: GatewayAttachement
|
|
||||||
Properties:
|
|
||||||
RouteTableId: !Ref 'PublicRouteTable'
|
|
||||||
DestinationCidrBlock: '0.0.0.0/0'
|
|
||||||
GatewayId: !Ref 'InternetGateway'
|
|
||||||
|
|
||||||
# Attaching a public route table makes a subnet public.
|
|
||||||
PublicSubnetOneRouteTableAssociation:
|
|
||||||
Type: AWS::EC2::SubnetRouteTableAssociation
|
|
||||||
Properties:
|
|
||||||
SubnetId: !Ref PublicSubnetOne
|
|
||||||
RouteTableId: !Ref PublicRouteTable
|
|
||||||
PublicSubnetTwoRouteTableAssociation:
|
|
||||||
Type: AWS::EC2::SubnetRouteTableAssociation
|
|
||||||
Properties:
|
|
||||||
SubnetId: !Ref PublicSubnetTwo
|
|
||||||
RouteTableId: !Ref PublicRouteTable
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ECS Resources
|
|
||||||
ECSCluster:
|
|
||||||
Type: AWS::ECS::Cluster
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# A role used to allow AWS Autoscaling to inspect stats and adjust scaleable targets
|
|
||||||
# on your AWS account
|
|
||||||
AutoscalingRole:
|
|
||||||
Type: AWS::IAM::Role
|
|
||||||
Properties:
|
|
||||||
AssumeRolePolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Principal:
|
|
||||||
Service: [application-autoscaling.amazonaws.com]
|
|
||||||
Action: ['sts:AssumeRole']
|
|
||||||
Path: /
|
|
||||||
Policies:
|
|
||||||
- PolicyName: service-autoscaling
|
|
||||||
PolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Action:
|
|
||||||
- 'application-autoscaling:*'
|
|
||||||
- 'cloudwatch:DescribeAlarms'
|
|
||||||
- 'cloudwatch:PutMetricAlarm'
|
|
||||||
- 'ecs:DescribeServices'
|
|
||||||
- 'ecs:UpdateService'
|
|
||||||
Resource: '*'
|
|
||||||
|
|
||||||
# This is an IAM role which authorizes ECS to manage resources on your
|
|
||||||
# account on your behalf, such as updating your load balancer with the
|
|
||||||
# details of where your containers are, so that traffic can reach your
|
|
||||||
# containers.
|
|
||||||
ECSRole:
|
|
||||||
Type: AWS::IAM::Role
|
|
||||||
Properties:
|
|
||||||
AssumeRolePolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Principal:
|
|
||||||
Service: [ecs.amazonaws.com]
|
|
||||||
Action: ['sts:AssumeRole']
|
|
||||||
Path: /
|
|
||||||
Policies:
|
|
||||||
- PolicyName: ecs-service
|
|
||||||
PolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Action:
|
|
||||||
# Rules which allow ECS to attach network interfaces to instances
|
|
||||||
# on your behalf in order for awsvpc networking mode to work right
|
|
||||||
- 'ec2:AttachNetworkInterface'
|
|
||||||
- 'ec2:CreateNetworkInterface'
|
|
||||||
- 'ec2:CreateNetworkInterfacePermission'
|
|
||||||
- 'ec2:DeleteNetworkInterface'
|
|
||||||
- 'ec2:DeleteNetworkInterfacePermission'
|
|
||||||
- 'ec2:Describe*'
|
|
||||||
- 'ec2:DetachNetworkInterface'
|
|
||||||
|
|
||||||
# Rules which allow ECS to update load balancers on your behalf
|
|
||||||
# with the information sabout how to send traffic to your containers
|
|
||||||
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
|
|
||||||
- 'elasticloadbalancing:DeregisterTargets'
|
|
||||||
- 'elasticloadbalancing:Describe*'
|
|
||||||
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
|
|
||||||
- 'elasticloadbalancing:RegisterTargets'
|
|
||||||
Resource: '*'
|
|
||||||
|
|
||||||
# This is a role which is used by the ECS tasks themselves.
|
|
||||||
ECSTaskExecutionRole:
|
|
||||||
Type: AWS::IAM::Role
|
|
||||||
Properties:
|
|
||||||
AssumeRolePolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Principal:
|
|
||||||
Service: [ecs-tasks.amazonaws.com]
|
|
||||||
Action: ['sts:AssumeRole']
|
|
||||||
Path: /
|
|
||||||
Policies:
|
|
||||||
- PolicyName: AmazonECSTaskExecutionRolePolicy
|
|
||||||
PolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Action:
|
|
||||||
|
|
||||||
# Allow the use of secret manager
|
|
||||||
- 'secretsmanager:GetSecretValue'
|
|
||||||
- 'kms:Decrypt'
|
|
||||||
|
|
||||||
# Allow the ECS Tasks to download images from ECR
|
|
||||||
- 'ecr:GetAuthorizationToken'
|
|
||||||
- 'ecr:BatchCheckLayerAvailability'
|
|
||||||
- 'ecr:GetDownloadUrlForLayer'
|
|
||||||
- 'ecr:BatchGetImage'
|
|
||||||
|
|
||||||
# Allow the ECS tasks to upload logs to CloudWatch
|
|
||||||
- 'logs:CreateLogStream'
|
|
||||||
- 'logs:PutLogEvents'
|
|
||||||
Resource: '*'
|
|
||||||
|
|
||||||
DeleteCFNLambdaExecutionRole:
|
|
||||||
Type: "AWS::IAM::Role"
|
|
||||||
Properties:
|
|
||||||
AssumeRolePolicyDocument:
|
|
||||||
Version: "2012-10-17"
|
|
||||||
Statement:
|
|
||||||
- Effect: "Allow"
|
|
||||||
Principal:
|
|
||||||
Service: ["lambda.amazonaws.com"]
|
|
||||||
Action: "sts:AssumeRole"
|
|
||||||
Path: "/"
|
|
||||||
Policies:
|
|
||||||
- PolicyName: DeleteCFNLambdaExecutionRole
|
|
||||||
PolicyDocument:
|
|
||||||
Version: "2012-10-17"
|
|
||||||
Statement:
|
|
||||||
- Effect: "Allow"
|
|
||||||
Action:
|
|
||||||
- "logs:CreateLogGroup"
|
|
||||||
- "logs:CreateLogStream"
|
|
||||||
- "logs:PutLogEvents"
|
|
||||||
Resource: "arn:aws:logs:*:*:*"
|
|
||||||
- Effect: "Allow"
|
|
||||||
Action:
|
|
||||||
- "cloudformation:DeleteStack"
|
|
||||||
- "kinesis:DeleteStream"
|
|
||||||
- "secretsmanager:DeleteSecret"
|
|
||||||
- "kinesis:DescribeStreamSummary"
|
|
||||||
- "logs:DeleteLogGroup"
|
|
||||||
- "logs:DeleteSubscriptionFilter"
|
|
||||||
- "ecs:DeregisterTaskDefinition"
|
|
||||||
- "lambda:DeleteFunction"
|
|
||||||
- "lambda:InvokeFunction"
|
|
||||||
- "events:RemoveTargets"
|
|
||||||
- "events:DeleteRule"
|
|
||||||
- "lambda:RemovePermission"
|
|
||||||
Resource: "*"
|
|
||||||
|
|
||||||
### cloud watch to kinesis role
|
|
||||||
|
|
||||||
CloudWatchIAMRole:
|
|
||||||
Type: AWS::IAM::Role
|
|
||||||
Properties:
|
|
||||||
AssumeRolePolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Principal:
|
|
||||||
Service: [logs.amazonaws.com]
|
|
||||||
Action: ['sts:AssumeRole']
|
|
||||||
Path: /
|
|
||||||
Policies:
|
|
||||||
- PolicyName: service-autoscaling
|
|
||||||
PolicyDocument:
|
|
||||||
Statement:
|
|
||||||
- Effect: Allow
|
|
||||||
Action:
|
|
||||||
- 'kinesis:PutRecord'
|
|
||||||
Resource: '*'
|
|
||||||
#####################EFS#####################
|
|
||||||
|
|
||||||
EfsFileStorage:
|
|
||||||
Type: 'AWS::EFS::FileSystem'
|
|
||||||
Properties:
|
|
||||||
BackupPolicy:
|
|
||||||
Status: ENABLED
|
|
||||||
PerformanceMode: maxIO
|
|
||||||
Encrypted: false
|
|
||||||
|
|
||||||
|
|
||||||
FileSystemPolicy:
|
|
||||||
Version: "2012-10-17"
|
|
||||||
Statement:
|
|
||||||
- Effect: "Allow"
|
|
||||||
Action:
|
|
||||||
- "elasticfilesystem:ClientMount"
|
|
||||||
- "elasticfilesystem:ClientWrite"
|
|
||||||
- "elasticfilesystem:ClientRootAccess"
|
|
||||||
Principal:
|
|
||||||
AWS: "*"
|
|
||||||
|
|
||||||
|
|
||||||
MountTargetResource1:
|
|
||||||
Type: AWS::EFS::MountTarget
|
|
||||||
Properties:
|
|
||||||
FileSystemId: !Ref EfsFileStorage
|
|
||||||
SubnetId: !Ref PublicSubnetOne
|
|
||||||
SecurityGroups:
|
|
||||||
- !Ref EFSServerSecurityGroup
|
|
||||||
|
|
||||||
MountTargetResource2:
|
|
||||||
Type: AWS::EFS::MountTarget
|
|
||||||
Properties:
|
|
||||||
FileSystemId: !Ref EfsFileStorage
|
|
||||||
SubnetId: !Ref PublicSubnetTwo
|
|
||||||
SecurityGroups:
|
|
||||||
- !Ref EFSServerSecurityGroup
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Outputs:
|
|
||||||
|
|
||||||
EfsFileStorageId:
|
|
||||||
Description: 'The connection endpoint for the database.'
|
|
||||||
Value: !Ref EfsFileStorage
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:EfsFileStorageId
|
|
||||||
ClusterName:
|
|
||||||
Description: The name of the ECS cluster
|
|
||||||
Value: !Ref 'ECSCluster'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:ClusterName
|
|
||||||
AutoscalingRole:
|
|
||||||
Description: The ARN of the role used for autoscaling
|
|
||||||
Value: !GetAtt 'AutoscalingRole.Arn'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:AutoscalingRole
|
|
||||||
ECSRole:
|
|
||||||
Description: The ARN of the ECS role
|
|
||||||
Value: !GetAtt 'ECSRole.Arn'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:ECSRole
|
|
||||||
ECSTaskExecutionRole:
|
|
||||||
Description: The ARN of the ECS role tsk execution role
|
|
||||||
Value: !GetAtt 'ECSTaskExecutionRole.Arn'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:ECSTaskExecutionRole
|
|
||||||
|
|
||||||
DeleteCFNLambdaExecutionRole:
|
|
||||||
Description: Lambda execution role for cleaning up cloud formations
|
|
||||||
Value: !GetAtt 'DeleteCFNLambdaExecutionRole.Arn'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:DeleteCFNLambdaExecutionRole
|
|
||||||
|
|
||||||
CloudWatchIAMRole:
|
|
||||||
Description: The ARN of the CloudWatch role for subscription filter
|
|
||||||
Value: !GetAtt 'CloudWatchIAMRole.Arn'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:CloudWatchIAMRole
|
|
||||||
VpcId:
|
|
||||||
Description: The ID of the VPC that this stack is deployed in
|
|
||||||
Value: !Ref 'VPC'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:VpcId
|
|
||||||
PublicSubnetOne:
|
|
||||||
Description: Public subnet one
|
|
||||||
Value: !Ref 'PublicSubnetOne'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:PublicSubnetOne
|
|
||||||
PublicSubnetTwo:
|
|
||||||
Description: Public subnet two
|
|
||||||
Value: !Ref 'PublicSubnetTwo'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:PublicSubnetTwo
|
|
||||||
|
|
||||||
ContainerSecurityGroup:
|
|
||||||
Description: A security group used to allow Fargate containers to receive traffic
|
|
||||||
Value: !Ref 'ContainerSecurityGroup'
|
|
||||||
Export:
|
|
||||||
Name: !Sub ${EnvironmentName}:ContainerSecurityGroup
|
|
||||||
|
|
@ -1,221 +0,0 @@
|
||||||
AWSTemplateFormatVersion: 2010-09-09
|
|
||||||
Description: >-
|
|
||||||
AWS Fargate cluster that can span public and private subnets. Supports public
|
|
||||||
facing load balancers, private internal load balancers, and both internal and
|
|
||||||
external service discovery namespaces.
|
|
||||||
Parameters:
|
|
||||||
EnvironmentName:
|
|
||||||
Type: String
|
|
||||||
Default: development
|
|
||||||
Description: 'Your deployment environment: DEV, QA , PROD'
|
|
||||||
ServiceName:
|
|
||||||
Type: String
|
|
||||||
Default: example
|
|
||||||
Description: A name for the service
|
|
||||||
ImageUrl:
|
|
||||||
Type: String
|
|
||||||
Default: nginx
|
|
||||||
Description: >-
|
|
||||||
The url of a docker image that contains the application process that will
|
|
||||||
handle the traffic for this service
|
|
||||||
ContainerPort:
|
|
||||||
Type: Number
|
|
||||||
Default: 80
|
|
||||||
Description: What port number the application inside the docker container is binding to
|
|
||||||
ContainerCpu:
|
|
||||||
Type: Number
|
|
||||||
Default: 1024
|
|
||||||
Description: How much CPU to give the container. 1024 is 1 CPU
|
|
||||||
ContainerMemory:
|
|
||||||
Type: Number
|
|
||||||
Default: 2048
|
|
||||||
Description: How much memory in megabytes to give the container
|
|
||||||
BUILDGUID:
|
|
||||||
Type: String
|
|
||||||
Default: ''
|
|
||||||
Command:
|
|
||||||
Type: String
|
|
||||||
Default: 'ls'
|
|
||||||
EntryPoint:
|
|
||||||
Type: String
|
|
||||||
Default: '/bin/sh'
|
|
||||||
WorkingDirectory:
|
|
||||||
Type: String
|
|
||||||
Default: '/efsdata/'
|
|
||||||
Role:
|
|
||||||
Type: String
|
|
||||||
Default: ''
|
|
||||||
Description: >-
|
|
||||||
(Optional) An IAM role to give the service's containers if the code within
|
|
||||||
needs to access other AWS resources
|
|
||||||
EFSMountDirectory:
|
|
||||||
Type: String
|
|
||||||
Default: '/efsdata'
|
|
||||||
# template secrets p1 - input
|
|
||||||
Mappings:
|
|
||||||
SubnetConfig:
|
|
||||||
VPC:
|
|
||||||
CIDR: 10.0.0.0/16
|
|
||||||
PublicOne:
|
|
||||||
CIDR: 10.0.0.0/24
|
|
||||||
PublicTwo:
|
|
||||||
CIDR: 10.0.1.0/24
|
|
||||||
Conditions:
|
|
||||||
HasCustomRole: !Not
|
|
||||||
- !Equals
|
|
||||||
- Ref: Role
|
|
||||||
- ''
|
|
||||||
Resources:
|
|
||||||
LogGroup:
|
|
||||||
Type: 'AWS::Logs::LogGroup'
|
|
||||||
Properties:
|
|
||||||
LogGroupName: !Ref ServiceName
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
SubscriptionFilter:
|
|
||||||
Type: 'AWS::Logs::SubscriptionFilter'
|
|
||||||
Properties:
|
|
||||||
FilterPattern: ''
|
|
||||||
RoleArn:
|
|
||||||
'Fn::ImportValue': !Sub '${EnvironmentName}:CloudWatchIAMRole'
|
|
||||||
LogGroupName: !Ref ServiceName
|
|
||||||
DestinationArn:
|
|
||||||
'Fn::GetAtt':
|
|
||||||
- KinesisStream
|
|
||||||
- Arn
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
|
||||||
DependsOn:
|
|
||||||
- LogGroup
|
|
||||||
- KinesisStream
|
|
||||||
KinesisStream:
|
|
||||||
Type: 'AWS::Kinesis::Stream'
|
|
||||||
Properties:
|
|
||||||
Name: !Ref ServiceName
|
|
||||||
ShardCount: 1
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: c6f18447-b879-4696-8873-f981b2cedd2b
|
|
||||||
|
|
||||||
# template secrets p2 - secret
|
|
||||||
|
|
||||||
TaskDefinition:
|
|
||||||
Type: 'AWS::ECS::TaskDefinition'
|
|
||||||
Properties:
|
|
||||||
Family: !Ref ServiceName
|
|
||||||
Cpu: !Ref ContainerCpu
|
|
||||||
Memory: !Ref ContainerMemory
|
|
||||||
NetworkMode: awsvpc
|
|
||||||
Volumes:
|
|
||||||
- Name: efs-data
|
|
||||||
EFSVolumeConfiguration:
|
|
||||||
FilesystemId:
|
|
||||||
'Fn::ImportValue': !Sub '${EnvironmentName}:EfsFileStorageId'
|
|
||||||
TransitEncryption: ENABLED
|
|
||||||
RequiresCompatibilities:
|
|
||||||
- FARGATE
|
|
||||||
ExecutionRoleArn:
|
|
||||||
'Fn::ImportValue': !Sub '${EnvironmentName}:ECSTaskExecutionRole'
|
|
||||||
TaskRoleArn:
|
|
||||||
'Fn::If':
|
|
||||||
- HasCustomRole
|
|
||||||
- !Ref Role
|
|
||||||
- !Ref 'AWS::NoValue'
|
|
||||||
ContainerDefinitions:
|
|
||||||
- Name: !Ref ServiceName
|
|
||||||
Cpu: !Ref ContainerCpu
|
|
||||||
Memory: !Ref ContainerMemory
|
|
||||||
Image: !Ref ImageUrl
|
|
||||||
EntryPoint:
|
|
||||||
Fn::Split:
|
|
||||||
- ","
|
|
||||||
- !Ref EntryPoint
|
|
||||||
Command:
|
|
||||||
Fn::Split:
|
|
||||||
- ","
|
|
||||||
- !Ref Command
|
|
||||||
WorkingDirectory: !Ref WorkingDirectory
|
|
||||||
Environment:
|
|
||||||
- Name: ALLOW_EMPTY_PASSWORD
|
|
||||||
Value: 'yes'
|
|
||||||
# template - env vars
|
|
||||||
MountPoints:
|
|
||||||
- SourceVolume: efs-data
|
|
||||||
ContainerPath: !Ref EFSMountDirectory
|
|
||||||
ReadOnly: false
|
|
||||||
Secrets:
|
|
||||||
# template secrets p3 - container def
|
|
||||||
LogConfiguration:
|
|
||||||
LogDriver: awslogs
|
|
||||||
Options:
|
|
||||||
awslogs-group: !Ref ServiceName
|
|
||||||
awslogs-region: !Ref 'AWS::Region'
|
|
||||||
awslogs-stream-prefix: !Ref ServiceName
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: dabb0116-abe0-48a6-a8af-cf9111c879a5
|
|
||||||
DependsOn:
|
|
||||||
- LogGroup
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
dabb0116-abe0-48a6-a8af-cf9111c879a5:
|
|
||||||
size:
|
|
||||||
width: 60
|
|
||||||
height: 60
|
|
||||||
position:
|
|
||||||
x: 270
|
|
||||||
'y': 90
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
dependson:
|
|
||||||
- aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
c6f18447-b879-4696-8873-f981b2cedd2b:
|
|
||||||
size:
|
|
||||||
width: 60
|
|
||||||
height: 60
|
|
||||||
position:
|
|
||||||
x: 270
|
|
||||||
'y': 210
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
7f809e91-9e5d-4678-98c1-c5085956c480:
|
|
||||||
size:
|
|
||||||
width: 60
|
|
||||||
height: 60
|
|
||||||
position:
|
|
||||||
x: 60
|
|
||||||
'y': 300
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
dependson:
|
|
||||||
- aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
- c6f18447-b879-4696-8873-f981b2cedd2b
|
|
||||||
aece53ae-b82d-4267-bc16-ed964b05db27:
|
|
||||||
size:
|
|
||||||
width: 150
|
|
||||||
height: 150
|
|
||||||
position:
|
|
||||||
x: 60
|
|
||||||
'y': 90
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
4d2da56c-3643-46b8-aaee-e46e19f95fcc:
|
|
||||||
source:
|
|
||||||
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
|
||||||
target:
|
|
||||||
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
z: 11
|
|
||||||
14eb957b-f094-4653-93c4-77b2f851953c:
|
|
||||||
source:
|
|
||||||
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
|
||||||
target:
|
|
||||||
id: c6f18447-b879-4696-8873-f981b2cedd2b
|
|
||||||
z: 12
|
|
||||||
85c57444-e5bb-4230-bc85-e545cd4558f6:
|
|
||||||
source:
|
|
||||||
id: dabb0116-abe0-48a6-a8af-cf9111c879a5
|
|
||||||
target:
|
|
||||||
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
z: 13
|
|
||||||
|
|
@ -814,8 +814,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.AWSBaseStack = void 0;
|
exports.AWSBaseStack = void 0;
|
||||||
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
|
||||||
const core = __importStar(__nccwpck_require__(42186));
|
const core = __importStar(__nccwpck_require__(42186));
|
||||||
const fs = __importStar(__nccwpck_require__(57147));
|
const base_stack_formation_1 = __nccwpck_require__(29643);
|
||||||
const path_1 = __importDefault(__nccwpck_require__(71017));
|
|
||||||
const crypto = __nccwpck_require__(6113);
|
const crypto = __nccwpck_require__(6113);
|
||||||
class AWSBaseStack {
|
class AWSBaseStack {
|
||||||
constructor(baseStackName) {
|
constructor(baseStackName) {
|
||||||
|
|
@ -825,7 +824,7 @@ class AWSBaseStack {
|
||||||
var _a, _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const baseStackName = this.baseStackName;
|
const baseStackName = this.baseStackName;
|
||||||
const baseStack = fs.readFileSync(path_1.default.join(__dirname, 'cloud-formations', 'base-setup.yml'), 'utf8');
|
const baseStack = base_stack_formation_1.BaseStackFormation.formation;
|
||||||
// Cloud Formation Input
|
// Cloud Formation Input
|
||||||
const describeStackInput = {
|
const describeStackInput = {
|
||||||
StackName: baseStackName,
|
StackName: baseStackName,
|
||||||
|
|
@ -920,32 +919,13 @@ exports.AWSBaseStack = AWSBaseStack;
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 54837:
|
/***/ 54837:
|
||||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
||||||
}) : (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
o[k2] = m[k];
|
|
||||||
}));
|
|
||||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
||||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
||||||
}) : function(o, v) {
|
|
||||||
o["default"] = v;
|
|
||||||
});
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.AWSCloudFormationTemplates = void 0;
|
exports.AWSCloudFormationTemplates = void 0;
|
||||||
const fs = __importStar(__nccwpck_require__(57147));
|
const task_definition_formation_1 = __nccwpck_require__(97647);
|
||||||
class AWSCloudFormationTemplates {
|
class AWSCloudFormationTemplates {
|
||||||
static getParameterTemplate(p1) {
|
static getParameterTemplate(p1) {
|
||||||
return `
|
return `
|
||||||
|
|
@ -975,7 +955,7 @@ class AWSCloudFormationTemplates {
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
static readTaskCloudFormationTemplate() {
|
static readTaskCloudFormationTemplate() {
|
||||||
return fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8');
|
return task_definition_formation_1.TaskDefinitionFormation.formation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.AWSCloudFormationTemplates = AWSCloudFormationTemplates;
|
exports.AWSCloudFormationTemplates = AWSCloudFormationTemplates;
|
||||||
|
|
@ -1416,6 +1396,581 @@ class AWSTaskRunner {
|
||||||
exports["default"] = AWSTaskRunner;
|
exports["default"] = AWSTaskRunner;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 29643:
|
||||||
|
/***/ ((__unused_webpack_module, exports) => {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.BaseStackFormation = void 0;
|
||||||
|
class BaseStackFormation {
|
||||||
|
}
|
||||||
|
exports.BaseStackFormation = BaseStackFormation;
|
||||||
|
BaseStackFormation.formation = ` AWSTemplateFormatVersion: '2010-09-09'
|
||||||
|
Description: Game-CI base stack
|
||||||
|
Parameters:
|
||||||
|
EnvironmentName:
|
||||||
|
Type: String
|
||||||
|
Default: development
|
||||||
|
Description: 'Your deployment environment: DEV, QA , PROD'
|
||||||
|
Version:
|
||||||
|
Type: String
|
||||||
|
Description: 'hash of template'
|
||||||
|
|
||||||
|
# ContainerPort:
|
||||||
|
# Type: Number
|
||||||
|
# Default: 80
|
||||||
|
# Description: What port number the application inside the docker container is binding to
|
||||||
|
|
||||||
|
Mappings:
|
||||||
|
# Hard values for the subnet masks. These masks define
|
||||||
|
# the range of internal IP addresses that can be assigned.
|
||||||
|
# The VPC can have all IP's from 10.0.0.0 to 10.0.255.255
|
||||||
|
# There are four subnets which cover the ranges:
|
||||||
|
#
|
||||||
|
# 10.0.0.0 - 10.0.0.255
|
||||||
|
# 10.0.1.0 - 10.0.1.255
|
||||||
|
# 10.0.2.0 - 10.0.2.255
|
||||||
|
# 10.0.3.0 - 10.0.3.255
|
||||||
|
|
||||||
|
SubnetConfig:
|
||||||
|
VPC:
|
||||||
|
CIDR: '10.0.0.0/16'
|
||||||
|
PublicOne:
|
||||||
|
CIDR: '10.0.0.0/24'
|
||||||
|
PublicTwo:
|
||||||
|
CIDR: '10.0.1.0/24'
|
||||||
|
|
||||||
|
Resources:
|
||||||
|
# VPC in which containers will be networked.
|
||||||
|
# It has two public subnets, and two private subnets.
|
||||||
|
# We distribute the subnets across the first two available subnets
|
||||||
|
# for the region, for high availability.
|
||||||
|
VPC:
|
||||||
|
Type: AWS::EC2::VPC
|
||||||
|
Properties:
|
||||||
|
EnableDnsSupport: true
|
||||||
|
EnableDnsHostnames: true
|
||||||
|
CidrBlock: !FindInMap ['SubnetConfig', 'VPC', 'CIDR']
|
||||||
|
|
||||||
|
EFSServerSecurityGroup:
|
||||||
|
Type: AWS::EC2::SecurityGroup
|
||||||
|
Properties:
|
||||||
|
GroupName: 'efs-server-endpoints'
|
||||||
|
GroupDescription: Which client ip addrs are allowed to access EFS server
|
||||||
|
VpcId: !Ref 'VPC'
|
||||||
|
SecurityGroupIngress:
|
||||||
|
- IpProtocol: tcp
|
||||||
|
FromPort: 2049
|
||||||
|
ToPort: 2049
|
||||||
|
SourceSecurityGroupId: !Ref ContainerSecurityGroup
|
||||||
|
#CidrIp: !FindInMap ['SubnetConfig', 'VPC', 'CIDR']
|
||||||
|
# A security group for the containers we will run in Fargate.
|
||||||
|
# Rules are added to this security group based on what ingress you
|
||||||
|
# add for the cluster.
|
||||||
|
ContainerSecurityGroup:
|
||||||
|
Type: AWS::EC2::SecurityGroup
|
||||||
|
Properties:
|
||||||
|
GroupName: 'task security group'
|
||||||
|
GroupDescription: Access to the Fargate containers
|
||||||
|
VpcId: !Ref 'VPC'
|
||||||
|
# SecurityGroupIngress:
|
||||||
|
# - IpProtocol: tcp
|
||||||
|
# FromPort: !Ref ContainerPort
|
||||||
|
# ToPort: !Ref ContainerPort
|
||||||
|
# CidrIp: 0.0.0.0/0
|
||||||
|
SecurityGroupEgress:
|
||||||
|
- IpProtocol: -1
|
||||||
|
FromPort: 2049
|
||||||
|
ToPort: 2049
|
||||||
|
CidrIp: '0.0.0.0/0'
|
||||||
|
|
||||||
|
# Two public subnets, where containers can have public IP addresses
|
||||||
|
PublicSubnetOne:
|
||||||
|
Type: AWS::EC2::Subnet
|
||||||
|
Properties:
|
||||||
|
AvailabilityZone: !Select
|
||||||
|
- 0
|
||||||
|
- Fn::GetAZs: !Ref 'AWS::Region'
|
||||||
|
VpcId: !Ref 'VPC'
|
||||||
|
CidrBlock: !FindInMap ['SubnetConfig', 'PublicOne', 'CIDR']
|
||||||
|
# MapPublicIpOnLaunch: true
|
||||||
|
|
||||||
|
PublicSubnetTwo:
|
||||||
|
Type: AWS::EC2::Subnet
|
||||||
|
Properties:
|
||||||
|
AvailabilityZone: !Select
|
||||||
|
- 1
|
||||||
|
- Fn::GetAZs: !Ref 'AWS::Region'
|
||||||
|
VpcId: !Ref 'VPC'
|
||||||
|
CidrBlock: !FindInMap ['SubnetConfig', 'PublicTwo', 'CIDR']
|
||||||
|
# MapPublicIpOnLaunch: true
|
||||||
|
|
||||||
|
# Setup networking resources for the public subnets. Containers
|
||||||
|
# in the public subnets have public IP addresses and the routing table
|
||||||
|
# sends network traffic via the internet gateway.
|
||||||
|
InternetGateway:
|
||||||
|
Type: AWS::EC2::InternetGateway
|
||||||
|
GatewayAttachement:
|
||||||
|
Type: AWS::EC2::VPCGatewayAttachment
|
||||||
|
Properties:
|
||||||
|
VpcId: !Ref 'VPC'
|
||||||
|
InternetGatewayId: !Ref 'InternetGateway'
|
||||||
|
|
||||||
|
# Attaching a Internet Gateway to route table makes it public.
|
||||||
|
PublicRouteTable:
|
||||||
|
Type: AWS::EC2::RouteTable
|
||||||
|
Properties:
|
||||||
|
VpcId: !Ref 'VPC'
|
||||||
|
PublicRoute:
|
||||||
|
Type: AWS::EC2::Route
|
||||||
|
DependsOn: GatewayAttachement
|
||||||
|
Properties:
|
||||||
|
RouteTableId: !Ref 'PublicRouteTable'
|
||||||
|
DestinationCidrBlock: '0.0.0.0/0'
|
||||||
|
GatewayId: !Ref 'InternetGateway'
|
||||||
|
|
||||||
|
# Attaching a public route table makes a subnet public.
|
||||||
|
PublicSubnetOneRouteTableAssociation:
|
||||||
|
Type: AWS::EC2::SubnetRouteTableAssociation
|
||||||
|
Properties:
|
||||||
|
SubnetId: !Ref PublicSubnetOne
|
||||||
|
RouteTableId: !Ref PublicRouteTable
|
||||||
|
PublicSubnetTwoRouteTableAssociation:
|
||||||
|
Type: AWS::EC2::SubnetRouteTableAssociation
|
||||||
|
Properties:
|
||||||
|
SubnetId: !Ref PublicSubnetTwo
|
||||||
|
RouteTableId: !Ref PublicRouteTable
|
||||||
|
|
||||||
|
# ECS Resources
|
||||||
|
ECSCluster:
|
||||||
|
Type: AWS::ECS::Cluster
|
||||||
|
|
||||||
|
# A role used to allow AWS Autoscaling to inspect stats and adjust scaleable targets
|
||||||
|
# on your AWS account
|
||||||
|
AutoscalingRole:
|
||||||
|
Type: AWS::IAM::Role
|
||||||
|
Properties:
|
||||||
|
AssumeRolePolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Principal:
|
||||||
|
Service: [application-autoscaling.amazonaws.com]
|
||||||
|
Action: ['sts:AssumeRole']
|
||||||
|
Path: /
|
||||||
|
Policies:
|
||||||
|
- PolicyName: service-autoscaling
|
||||||
|
PolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Action:
|
||||||
|
- 'application-autoscaling:*'
|
||||||
|
- 'cloudwatch:DescribeAlarms'
|
||||||
|
- 'cloudwatch:PutMetricAlarm'
|
||||||
|
- 'ecs:DescribeServices'
|
||||||
|
- 'ecs:UpdateService'
|
||||||
|
Resource: '*'
|
||||||
|
|
||||||
|
# This is an IAM role which authorizes ECS to manage resources on your
|
||||||
|
# account on your behalf, such as updating your load balancer with the
|
||||||
|
# details of where your containers are, so that traffic can reach your
|
||||||
|
# containers.
|
||||||
|
ECSRole:
|
||||||
|
Type: AWS::IAM::Role
|
||||||
|
Properties:
|
||||||
|
AssumeRolePolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Principal:
|
||||||
|
Service: [ecs.amazonaws.com]
|
||||||
|
Action: ['sts:AssumeRole']
|
||||||
|
Path: /
|
||||||
|
Policies:
|
||||||
|
- PolicyName: ecs-service
|
||||||
|
PolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Action:
|
||||||
|
# Rules which allow ECS to attach network interfaces to instances
|
||||||
|
# on your behalf in order for awsvpc networking mode to work right
|
||||||
|
- 'ec2:AttachNetworkInterface'
|
||||||
|
- 'ec2:CreateNetworkInterface'
|
||||||
|
- 'ec2:CreateNetworkInterfacePermission'
|
||||||
|
- 'ec2:DeleteNetworkInterface'
|
||||||
|
- 'ec2:DeleteNetworkInterfacePermission'
|
||||||
|
- 'ec2:Describe*'
|
||||||
|
- 'ec2:DetachNetworkInterface'
|
||||||
|
|
||||||
|
# Rules which allow ECS to update load balancers on your behalf
|
||||||
|
# with the information sabout how to send traffic to your containers
|
||||||
|
- 'elasticloadbalancing:DeregisterInstancesFromLoadBalancer'
|
||||||
|
- 'elasticloadbalancing:DeregisterTargets'
|
||||||
|
- 'elasticloadbalancing:Describe*'
|
||||||
|
- 'elasticloadbalancing:RegisterInstancesWithLoadBalancer'
|
||||||
|
- 'elasticloadbalancing:RegisterTargets'
|
||||||
|
Resource: '*'
|
||||||
|
|
||||||
|
# This is a role which is used by the ECS tasks themselves.
|
||||||
|
ECSTaskExecutionRole:
|
||||||
|
Type: AWS::IAM::Role
|
||||||
|
Properties:
|
||||||
|
AssumeRolePolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Principal:
|
||||||
|
Service: [ecs-tasks.amazonaws.com]
|
||||||
|
Action: ['sts:AssumeRole']
|
||||||
|
Path: /
|
||||||
|
Policies:
|
||||||
|
- PolicyName: AmazonECSTaskExecutionRolePolicy
|
||||||
|
PolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Action:
|
||||||
|
# Allow the use of secret manager
|
||||||
|
- 'secretsmanager:GetSecretValue'
|
||||||
|
- 'kms:Decrypt'
|
||||||
|
|
||||||
|
# Allow the ECS Tasks to download images from ECR
|
||||||
|
- 'ecr:GetAuthorizationToken'
|
||||||
|
- 'ecr:BatchCheckLayerAvailability'
|
||||||
|
- 'ecr:GetDownloadUrlForLayer'
|
||||||
|
- 'ecr:BatchGetImage'
|
||||||
|
|
||||||
|
# Allow the ECS tasks to upload logs to CloudWatch
|
||||||
|
- 'logs:CreateLogStream'
|
||||||
|
- 'logs:PutLogEvents'
|
||||||
|
Resource: '*'
|
||||||
|
|
||||||
|
DeleteCFNLambdaExecutionRole:
|
||||||
|
Type: 'AWS::IAM::Role'
|
||||||
|
Properties:
|
||||||
|
AssumeRolePolicyDocument:
|
||||||
|
Version: '2012-10-17'
|
||||||
|
Statement:
|
||||||
|
- Effect: 'Allow'
|
||||||
|
Principal:
|
||||||
|
Service: ['lambda.amazonaws.com']
|
||||||
|
Action: 'sts:AssumeRole'
|
||||||
|
Path: '/'
|
||||||
|
Policies:
|
||||||
|
- PolicyName: DeleteCFNLambdaExecutionRole
|
||||||
|
PolicyDocument:
|
||||||
|
Version: '2012-10-17'
|
||||||
|
Statement:
|
||||||
|
- Effect: 'Allow'
|
||||||
|
Action:
|
||||||
|
- 'logs:CreateLogGroup'
|
||||||
|
- 'logs:CreateLogStream'
|
||||||
|
- 'logs:PutLogEvents'
|
||||||
|
Resource: 'arn:aws:logs:*:*:*'
|
||||||
|
- Effect: 'Allow'
|
||||||
|
Action:
|
||||||
|
- 'cloudformation:DeleteStack'
|
||||||
|
- 'kinesis:DeleteStream'
|
||||||
|
- 'secretsmanager:DeleteSecret'
|
||||||
|
- 'kinesis:DescribeStreamSummary'
|
||||||
|
- 'logs:DeleteLogGroup'
|
||||||
|
- 'logs:DeleteSubscriptionFilter'
|
||||||
|
- 'ecs:DeregisterTaskDefinition'
|
||||||
|
- 'lambda:DeleteFunction'
|
||||||
|
- 'lambda:InvokeFunction'
|
||||||
|
- 'events:RemoveTargets'
|
||||||
|
- 'events:DeleteRule'
|
||||||
|
- 'lambda:RemovePermission'
|
||||||
|
Resource: '*'
|
||||||
|
|
||||||
|
### cloud watch to kinesis role
|
||||||
|
CloudWatchIAMRole:
|
||||||
|
Type: AWS::IAM::Role
|
||||||
|
Properties:
|
||||||
|
AssumeRolePolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Principal:
|
||||||
|
Service: [logs.amazonaws.com]
|
||||||
|
Action: ['sts:AssumeRole']
|
||||||
|
Path: /
|
||||||
|
Policies:
|
||||||
|
- PolicyName: service-autoscaling
|
||||||
|
PolicyDocument:
|
||||||
|
Statement:
|
||||||
|
- Effect: Allow
|
||||||
|
Action:
|
||||||
|
- 'kinesis:PutRecord'
|
||||||
|
Resource: '*'
|
||||||
|
|
||||||
|
#####################EFS#####################
|
||||||
|
EfsFileStorage:
|
||||||
|
Type: 'AWS::EFS::FileSystem'
|
||||||
|
Properties:
|
||||||
|
BackupPolicy:
|
||||||
|
Status: ENABLED
|
||||||
|
PerformanceMode: maxIO
|
||||||
|
Encrypted: false
|
||||||
|
|
||||||
|
FileSystemPolicy:
|
||||||
|
Version: '2012-10-17'
|
||||||
|
Statement:
|
||||||
|
- Effect: 'Allow'
|
||||||
|
Action:
|
||||||
|
- 'elasticfilesystem:ClientMount'
|
||||||
|
- 'elasticfilesystem:ClientWrite'
|
||||||
|
- 'elasticfilesystem:ClientRootAccess'
|
||||||
|
Principal:
|
||||||
|
AWS: '*'
|
||||||
|
|
||||||
|
MountTargetResource1:
|
||||||
|
Type: AWS::EFS::MountTarget
|
||||||
|
Properties:
|
||||||
|
FileSystemId: !Ref EfsFileStorage
|
||||||
|
SubnetId: !Ref PublicSubnetOne
|
||||||
|
SecurityGroups:
|
||||||
|
- !Ref EFSServerSecurityGroup
|
||||||
|
|
||||||
|
MountTargetResource2:
|
||||||
|
Type: AWS::EFS::MountTarget
|
||||||
|
Properties:
|
||||||
|
FileSystemId: !Ref EfsFileStorage
|
||||||
|
SubnetId: !Ref PublicSubnetTwo
|
||||||
|
SecurityGroups:
|
||||||
|
- !Ref EFSServerSecurityGroup
|
||||||
|
|
||||||
|
Outputs:
|
||||||
|
EfsFileStorageId:
|
||||||
|
Description: 'The connection endpoint for the database.'
|
||||||
|
Value: !Ref EfsFileStorage
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:EfsFileStorageId
|
||||||
|
ClusterName:
|
||||||
|
Description: The name of the ECS cluster
|
||||||
|
Value: !Ref 'ECSCluster'
|
||||||
|
Export:
|
||||||
|
Name: !Sub${' ${EnvironmentName}'}:ClusterName
|
||||||
|
AutoscalingRole:
|
||||||
|
Description: The ARN of the role used for autoscaling
|
||||||
|
Value: !GetAtt 'AutoscalingRole.Arn'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:AutoscalingRole
|
||||||
|
ECSRole:
|
||||||
|
Description: The ARN of the ECS role
|
||||||
|
Value: !GetAtt 'ECSRole.Arn'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:ECSRole
|
||||||
|
ECSTaskExecutionRole:
|
||||||
|
Description: The ARN of the ECS role tsk execution role
|
||||||
|
Value: !GetAtt 'ECSTaskExecutionRole.Arn'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:ECSTaskExecutionRole
|
||||||
|
|
||||||
|
DeleteCFNLambdaExecutionRole:
|
||||||
|
Description: Lambda execution role for cleaning up cloud formations
|
||||||
|
Value: !GetAtt 'DeleteCFNLambdaExecutionRole.Arn'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:DeleteCFNLambdaExecutionRole
|
||||||
|
|
||||||
|
CloudWatchIAMRole:
|
||||||
|
Description: The ARN of the CloudWatch role for subscription filter
|
||||||
|
Value: !GetAtt 'CloudWatchIAMRole.Arn'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:CloudWatchIAMRole
|
||||||
|
VpcId:
|
||||||
|
Description: The ID of the VPC that this stack is deployed in
|
||||||
|
Value: !Ref 'VPC'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:VpcId
|
||||||
|
PublicSubnetOne:
|
||||||
|
Description: Public subnet one
|
||||||
|
Value: !Ref 'PublicSubnetOne'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:PublicSubnetOne
|
||||||
|
PublicSubnetTwo:
|
||||||
|
Description: Public subnet two
|
||||||
|
Value: !Ref 'PublicSubnetTwo'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:PublicSubnetTwo
|
||||||
|
ContainerSecurityGroup:
|
||||||
|
Description: A security group used to allow Fargate containers to receive traffic
|
||||||
|
Value: !Ref 'ContainerSecurityGroup'
|
||||||
|
Export:
|
||||||
|
Name: !Sub ${'${EnvironmentName}'}:ContainerSecurityGroup
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 97647:
|
||||||
|
/***/ ((__unused_webpack_module, exports) => {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.TaskDefinitionFormation = void 0;
|
||||||
|
class TaskDefinitionFormation {
|
||||||
|
}
|
||||||
|
exports.TaskDefinitionFormation = TaskDefinitionFormation;
|
||||||
|
TaskDefinitionFormation.formation = ` AWSTemplateFormatVersion: 2010-09-09
|
||||||
|
Description: >-
|
||||||
|
AWS Fargate cluster that can span public and private subnets. Supports public
|
||||||
|
facing load balancers, private internal load balancers, and both internal and
|
||||||
|
external service discovery namespaces.
|
||||||
|
Parameters:
|
||||||
|
EnvironmentName:
|
||||||
|
Type: String
|
||||||
|
Default: development
|
||||||
|
Description: 'Your deployment environment: DEV, QA , PROD'
|
||||||
|
ServiceName:
|
||||||
|
Type: String
|
||||||
|
Default: example
|
||||||
|
Description: A name for the service
|
||||||
|
ImageUrl:
|
||||||
|
Type: String
|
||||||
|
Default: nginx
|
||||||
|
Description: >-
|
||||||
|
The url of a docker image that contains the application process that will
|
||||||
|
handle the traffic for this service
|
||||||
|
ContainerPort:
|
||||||
|
Type: Number
|
||||||
|
Default: 80
|
||||||
|
Description: What port number the application inside the docker container is binding to
|
||||||
|
ContainerCpu:
|
||||||
|
Type: Number
|
||||||
|
Default: 1024
|
||||||
|
Description: How much CPU to give the container. 1024 is 1 CPU
|
||||||
|
ContainerMemory:
|
||||||
|
Type: Number
|
||||||
|
Default: 2048
|
||||||
|
Description: How much memory in megabytes to give the container
|
||||||
|
BUILDGUID:
|
||||||
|
Type: String
|
||||||
|
Default: ''
|
||||||
|
Command:
|
||||||
|
Type: String
|
||||||
|
Default: 'ls'
|
||||||
|
EntryPoint:
|
||||||
|
Type: String
|
||||||
|
Default: '/bin/sh'
|
||||||
|
WorkingDirectory:
|
||||||
|
Type: String
|
||||||
|
Default: '/efsdata/'
|
||||||
|
Role:
|
||||||
|
Type: String
|
||||||
|
Default: ''
|
||||||
|
Description: >-
|
||||||
|
(Optional) An IAM role to give the service's containers if the code within
|
||||||
|
needs to access other AWS resources like S3 buckets, DynamoDB tables, etc
|
||||||
|
EFSMountDirectory:
|
||||||
|
Type: String
|
||||||
|
Default: '/efsdata'
|
||||||
|
# template secrets p1 - input
|
||||||
|
Mappings:
|
||||||
|
SubnetConfig:
|
||||||
|
VPC:
|
||||||
|
CIDR: 10.0.0.0/16
|
||||||
|
PublicOne:
|
||||||
|
CIDR: 10.0.0.0/24
|
||||||
|
PublicTwo:
|
||||||
|
CIDR: 10.0.1.0/24
|
||||||
|
Conditions:
|
||||||
|
HasCustomRole: !Not
|
||||||
|
- !Equals
|
||||||
|
- Ref: Role
|
||||||
|
- ''
|
||||||
|
Resources:
|
||||||
|
LogGroup:
|
||||||
|
Type: 'AWS::Logs::LogGroup'
|
||||||
|
Properties:
|
||||||
|
LogGroupName: !Ref ServiceName
|
||||||
|
Metadata:
|
||||||
|
'AWS::CloudFormation::Designer':
|
||||||
|
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
||||||
|
SubscriptionFilter:
|
||||||
|
Type: 'AWS::Logs::SubscriptionFilter'
|
||||||
|
Properties:
|
||||||
|
FilterPattern: ''
|
||||||
|
RoleArn:
|
||||||
|
'Fn::ImportValue': !Sub '${'${EnvironmentName}'}:CloudWatchIAMRole'
|
||||||
|
LogGroupName: !Ref ServiceName
|
||||||
|
DestinationArn:
|
||||||
|
'Fn::GetAtt':
|
||||||
|
- KinesisStream
|
||||||
|
- Arn
|
||||||
|
Metadata:
|
||||||
|
'AWS::CloudFormation::Designer':
|
||||||
|
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
||||||
|
DependsOn:
|
||||||
|
- LogGroup
|
||||||
|
- KinesisStream
|
||||||
|
KinesisStream:
|
||||||
|
Type: 'AWS::Kinesis::Stream'
|
||||||
|
Properties:
|
||||||
|
Name: !Ref ServiceName
|
||||||
|
ShardCount: 1
|
||||||
|
Metadata:
|
||||||
|
'AWS::CloudFormation::Designer':
|
||||||
|
id: c6f18447-b879-4696-8873-f981b2cedd2b
|
||||||
|
|
||||||
|
# template secrets p2 - secret
|
||||||
|
|
||||||
|
TaskDefinition:
|
||||||
|
Type: 'AWS::ECS::TaskDefinition'
|
||||||
|
Properties:
|
||||||
|
Family: !Ref ServiceName
|
||||||
|
Cpu: !Ref ContainerCpu
|
||||||
|
Memory: !Ref ContainerMemory
|
||||||
|
NetworkMode: awsvpc
|
||||||
|
Volumes:
|
||||||
|
- Name: efs-data
|
||||||
|
EFSVolumeConfiguration:
|
||||||
|
FilesystemId:
|
||||||
|
'Fn::ImportValue': !Sub '${'${EnvironmentName}'}:EfsFileStorageId'
|
||||||
|
TransitEncryption: ENABLED
|
||||||
|
RequiresCompatibilities:
|
||||||
|
- FARGATE
|
||||||
|
ExecutionRoleArn:
|
||||||
|
'Fn::ImportValue': !Sub '${'${EnvironmentName}'}:ECSTaskExecutionRole'
|
||||||
|
TaskRoleArn:
|
||||||
|
'Fn::If':
|
||||||
|
- HasCustomRole
|
||||||
|
- !Ref Role
|
||||||
|
- !Ref 'AWS::NoValue'
|
||||||
|
ContainerDefinitions:
|
||||||
|
- Name: !Ref ServiceName
|
||||||
|
Cpu: !Ref ContainerCpu
|
||||||
|
Memory: !Ref ContainerMemory
|
||||||
|
Image: !Ref ImageUrl
|
||||||
|
EntryPoint:
|
||||||
|
Fn::Split:
|
||||||
|
- ','
|
||||||
|
- !Ref EntryPoint
|
||||||
|
Command:
|
||||||
|
Fn::Split:
|
||||||
|
- ','
|
||||||
|
- !Ref Command
|
||||||
|
WorkingDirectory: !Ref WorkingDirectory
|
||||||
|
Environment:
|
||||||
|
- Name: ALLOW_EMPTY_PASSWORD
|
||||||
|
Value: 'yes'
|
||||||
|
# template - env vars
|
||||||
|
MountPoints:
|
||||||
|
- SourceVolume: efs-data
|
||||||
|
ContainerPath: !Ref EFSMountDirectory
|
||||||
|
ReadOnly: false
|
||||||
|
Secrets:
|
||||||
|
# template secrets p3 - container def
|
||||||
|
LogConfiguration:
|
||||||
|
LogDriver: awslogs
|
||||||
|
Options:
|
||||||
|
awslogs-group: !Ref ServiceName
|
||||||
|
awslogs-region: !Ref 'AWS::Region'
|
||||||
|
awslogs-stream-prefix: !Ref ServiceName
|
||||||
|
DependsOn:
|
||||||
|
- LogGroup
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 34340:
|
/***/ 34340:
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,8 +1,7 @@
|
||||||
import CloudRunnerLogger from '../../services/cloud-runner-logger';
|
import CloudRunnerLogger from '../../services/cloud-runner-logger';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as SDK from 'aws-sdk';
|
import * as SDK from 'aws-sdk';
|
||||||
import * as fs from 'fs';
|
import { BaseStackFormation } from './cloud-formations/base-stack-formation';
|
||||||
import path from 'path';
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
export class AWSBaseStack {
|
export class AWSBaseStack {
|
||||||
|
|
@ -14,7 +13,7 @@ export class AWSBaseStack {
|
||||||
async setupBaseStack(CF: SDK.CloudFormation) {
|
async setupBaseStack(CF: SDK.CloudFormation) {
|
||||||
const baseStackName = this.baseStackName;
|
const baseStackName = this.baseStackName;
|
||||||
|
|
||||||
const baseStack = fs.readFileSync(path.join(__dirname, 'cloud-formations', 'base-setup.yml'), 'utf8');
|
const baseStack = BaseStackFormation.formation;
|
||||||
|
|
||||||
// Cloud Formation Input
|
// Cloud Formation Input
|
||||||
const describeStackInput: SDK.CloudFormation.DescribeStacksInput = {
|
const describeStackInput: SDK.CloudFormation.DescribeStacksInput = {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import * as fs from 'fs';
|
import { TaskDefinitionFormation } from './cloud-formations/task-definition-formation';
|
||||||
|
|
||||||
export class AWSCloudFormationTemplates {
|
export class AWSCloudFormationTemplates {
|
||||||
public static getParameterTemplate(p1) {
|
public static getParameterTemplate(p1) {
|
||||||
|
|
@ -34,6 +34,6 @@ export class AWSCloudFormationTemplates {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readTaskCloudFormationTemplate(): string {
|
public static readTaskCloudFormationTemplate(): string {
|
||||||
return fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8');
|
return TaskDefinitionFormation.formation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
AWSTemplateFormatVersion: '2010-09-09'
|
export class BaseStackFormation {
|
||||||
|
public static readonly formation: string = ` AWSTemplateFormatVersion: '2010-09-09'
|
||||||
Description: Game-CI base stack
|
Description: Game-CI base stack
|
||||||
Parameters:
|
Parameters:
|
||||||
EnvironmentName:
|
EnvironmentName:
|
||||||
|
|
@ -333,57 +334,58 @@ Outputs:
|
||||||
Description: 'The connection endpoint for the database.'
|
Description: 'The connection endpoint for the database.'
|
||||||
Value: !Ref EfsFileStorage
|
Value: !Ref EfsFileStorage
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:EfsFileStorageId
|
Name: !Sub ${'${EnvironmentName}'}:EfsFileStorageId
|
||||||
ClusterName:
|
ClusterName:
|
||||||
Description: The name of the ECS cluster
|
Description: The name of the ECS cluster
|
||||||
Value: !Ref 'ECSCluster'
|
Value: !Ref 'ECSCluster'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:ClusterName
|
Name: !Sub${' ${EnvironmentName}'}:ClusterName
|
||||||
AutoscalingRole:
|
AutoscalingRole:
|
||||||
Description: The ARN of the role used for autoscaling
|
Description: The ARN of the role used for autoscaling
|
||||||
Value: !GetAtt 'AutoscalingRole.Arn'
|
Value: !GetAtt 'AutoscalingRole.Arn'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:AutoscalingRole
|
Name: !Sub ${'${EnvironmentName}'}:AutoscalingRole
|
||||||
ECSRole:
|
ECSRole:
|
||||||
Description: The ARN of the ECS role
|
Description: The ARN of the ECS role
|
||||||
Value: !GetAtt 'ECSRole.Arn'
|
Value: !GetAtt 'ECSRole.Arn'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:ECSRole
|
Name: !Sub ${'${EnvironmentName}'}:ECSRole
|
||||||
ECSTaskExecutionRole:
|
ECSTaskExecutionRole:
|
||||||
Description: The ARN of the ECS role tsk execution role
|
Description: The ARN of the ECS role tsk execution role
|
||||||
Value: !GetAtt 'ECSTaskExecutionRole.Arn'
|
Value: !GetAtt 'ECSTaskExecutionRole.Arn'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:ECSTaskExecutionRole
|
Name: !Sub ${'${EnvironmentName}'}:ECSTaskExecutionRole
|
||||||
|
|
||||||
DeleteCFNLambdaExecutionRole:
|
DeleteCFNLambdaExecutionRole:
|
||||||
Description: Lambda execution role for cleaning up cloud formations
|
Description: Lambda execution role for cleaning up cloud formations
|
||||||
Value: !GetAtt 'DeleteCFNLambdaExecutionRole.Arn'
|
Value: !GetAtt 'DeleteCFNLambdaExecutionRole.Arn'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:DeleteCFNLambdaExecutionRole
|
Name: !Sub ${'${EnvironmentName}'}:DeleteCFNLambdaExecutionRole
|
||||||
|
|
||||||
CloudWatchIAMRole:
|
CloudWatchIAMRole:
|
||||||
Description: The ARN of the CloudWatch role for subscription filter
|
Description: The ARN of the CloudWatch role for subscription filter
|
||||||
Value: !GetAtt 'CloudWatchIAMRole.Arn'
|
Value: !GetAtt 'CloudWatchIAMRole.Arn'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:CloudWatchIAMRole
|
Name: !Sub ${'${EnvironmentName}'}:CloudWatchIAMRole
|
||||||
VpcId:
|
VpcId:
|
||||||
Description: The ID of the VPC that this stack is deployed in
|
Description: The ID of the VPC that this stack is deployed in
|
||||||
Value: !Ref 'VPC'
|
Value: !Ref 'VPC'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:VpcId
|
Name: !Sub ${'${EnvironmentName}'}:VpcId
|
||||||
PublicSubnetOne:
|
PublicSubnetOne:
|
||||||
Description: Public subnet one
|
Description: Public subnet one
|
||||||
Value: !Ref 'PublicSubnetOne'
|
Value: !Ref 'PublicSubnetOne'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:PublicSubnetOne
|
Name: !Sub ${'${EnvironmentName}'}:PublicSubnetOne
|
||||||
PublicSubnetTwo:
|
PublicSubnetTwo:
|
||||||
Description: Public subnet two
|
Description: Public subnet two
|
||||||
Value: !Ref 'PublicSubnetTwo'
|
Value: !Ref 'PublicSubnetTwo'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:PublicSubnetTwo
|
Name: !Sub ${'${EnvironmentName}'}:PublicSubnetTwo
|
||||||
|
|
||||||
ContainerSecurityGroup:
|
ContainerSecurityGroup:
|
||||||
Description: A security group used to allow Fargate containers to receive traffic
|
Description: A security group used to allow Fargate containers to receive traffic
|
||||||
Value: !Ref 'ContainerSecurityGroup'
|
Value: !Ref 'ContainerSecurityGroup'
|
||||||
Export:
|
Export:
|
||||||
Name: !Sub ${EnvironmentName}:ContainerSecurityGroup
|
Name: !Sub ${'${EnvironmentName}'}:ContainerSecurityGroup
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
@ -1,221 +0,0 @@
|
||||||
AWSTemplateFormatVersion: 2010-09-09
|
|
||||||
Description: >-
|
|
||||||
AWS Fargate cluster that can span public and private subnets. Supports public
|
|
||||||
facing load balancers, private internal load balancers, and both internal and
|
|
||||||
external service discovery namespaces.
|
|
||||||
Parameters:
|
|
||||||
EnvironmentName:
|
|
||||||
Type: String
|
|
||||||
Default: development
|
|
||||||
Description: 'Your deployment environment: DEV, QA , PROD'
|
|
||||||
ServiceName:
|
|
||||||
Type: String
|
|
||||||
Default: example
|
|
||||||
Description: A name for the service
|
|
||||||
ImageUrl:
|
|
||||||
Type: String
|
|
||||||
Default: nginx
|
|
||||||
Description: >-
|
|
||||||
The url of a docker image that contains the application process that will
|
|
||||||
handle the traffic for this service
|
|
||||||
ContainerPort:
|
|
||||||
Type: Number
|
|
||||||
Default: 80
|
|
||||||
Description: What port number the application inside the docker container is binding to
|
|
||||||
ContainerCpu:
|
|
||||||
Type: Number
|
|
||||||
Default: 1024
|
|
||||||
Description: How much CPU to give the container. 1024 is 1 CPU
|
|
||||||
ContainerMemory:
|
|
||||||
Type: Number
|
|
||||||
Default: 2048
|
|
||||||
Description: How much memory in megabytes to give the container
|
|
||||||
BUILDGUID:
|
|
||||||
Type: String
|
|
||||||
Default: ''
|
|
||||||
Command:
|
|
||||||
Type: String
|
|
||||||
Default: 'ls'
|
|
||||||
EntryPoint:
|
|
||||||
Type: String
|
|
||||||
Default: '/bin/sh'
|
|
||||||
WorkingDirectory:
|
|
||||||
Type: String
|
|
||||||
Default: '/efsdata/'
|
|
||||||
Role:
|
|
||||||
Type: String
|
|
||||||
Default: ''
|
|
||||||
Description: >-
|
|
||||||
(Optional) An IAM role to give the service's containers if the code within
|
|
||||||
needs to access other AWS resources like S3 buckets, DynamoDB tables, etc
|
|
||||||
EFSMountDirectory:
|
|
||||||
Type: String
|
|
||||||
Default: '/efsdata'
|
|
||||||
# template secrets p1 - input
|
|
||||||
Mappings:
|
|
||||||
SubnetConfig:
|
|
||||||
VPC:
|
|
||||||
CIDR: 10.0.0.0/16
|
|
||||||
PublicOne:
|
|
||||||
CIDR: 10.0.0.0/24
|
|
||||||
PublicTwo:
|
|
||||||
CIDR: 10.0.1.0/24
|
|
||||||
Conditions:
|
|
||||||
HasCustomRole: !Not
|
|
||||||
- !Equals
|
|
||||||
- Ref: Role
|
|
||||||
- ''
|
|
||||||
Resources:
|
|
||||||
LogGroup:
|
|
||||||
Type: 'AWS::Logs::LogGroup'
|
|
||||||
Properties:
|
|
||||||
LogGroupName: !Ref ServiceName
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
SubscriptionFilter:
|
|
||||||
Type: 'AWS::Logs::SubscriptionFilter'
|
|
||||||
Properties:
|
|
||||||
FilterPattern: ''
|
|
||||||
RoleArn:
|
|
||||||
'Fn::ImportValue': !Sub '${EnvironmentName}:CloudWatchIAMRole'
|
|
||||||
LogGroupName: !Ref ServiceName
|
|
||||||
DestinationArn:
|
|
||||||
'Fn::GetAtt':
|
|
||||||
- KinesisStream
|
|
||||||
- Arn
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
|
||||||
DependsOn:
|
|
||||||
- LogGroup
|
|
||||||
- KinesisStream
|
|
||||||
KinesisStream:
|
|
||||||
Type: 'AWS::Kinesis::Stream'
|
|
||||||
Properties:
|
|
||||||
Name: !Ref ServiceName
|
|
||||||
ShardCount: 1
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: c6f18447-b879-4696-8873-f981b2cedd2b
|
|
||||||
|
|
||||||
# template secrets p2 - secret
|
|
||||||
|
|
||||||
TaskDefinition:
|
|
||||||
Type: 'AWS::ECS::TaskDefinition'
|
|
||||||
Properties:
|
|
||||||
Family: !Ref ServiceName
|
|
||||||
Cpu: !Ref ContainerCpu
|
|
||||||
Memory: !Ref ContainerMemory
|
|
||||||
NetworkMode: awsvpc
|
|
||||||
Volumes:
|
|
||||||
- Name: efs-data
|
|
||||||
EFSVolumeConfiguration:
|
|
||||||
FilesystemId:
|
|
||||||
'Fn::ImportValue': !Sub '${EnvironmentName}:EfsFileStorageId'
|
|
||||||
TransitEncryption: ENABLED
|
|
||||||
RequiresCompatibilities:
|
|
||||||
- FARGATE
|
|
||||||
ExecutionRoleArn:
|
|
||||||
'Fn::ImportValue': !Sub '${EnvironmentName}:ECSTaskExecutionRole'
|
|
||||||
TaskRoleArn:
|
|
||||||
'Fn::If':
|
|
||||||
- HasCustomRole
|
|
||||||
- !Ref Role
|
|
||||||
- !Ref 'AWS::NoValue'
|
|
||||||
ContainerDefinitions:
|
|
||||||
- Name: !Ref ServiceName
|
|
||||||
Cpu: !Ref ContainerCpu
|
|
||||||
Memory: !Ref ContainerMemory
|
|
||||||
Image: !Ref ImageUrl
|
|
||||||
EntryPoint:
|
|
||||||
Fn::Split:
|
|
||||||
- ','
|
|
||||||
- !Ref EntryPoint
|
|
||||||
Command:
|
|
||||||
Fn::Split:
|
|
||||||
- ','
|
|
||||||
- !Ref Command
|
|
||||||
WorkingDirectory: !Ref WorkingDirectory
|
|
||||||
Environment:
|
|
||||||
- Name: ALLOW_EMPTY_PASSWORD
|
|
||||||
Value: 'yes'
|
|
||||||
# template - env vars
|
|
||||||
MountPoints:
|
|
||||||
- SourceVolume: efs-data
|
|
||||||
ContainerPath: !Ref EFSMountDirectory
|
|
||||||
ReadOnly: false
|
|
||||||
Secrets:
|
|
||||||
# template secrets p3 - container def
|
|
||||||
LogConfiguration:
|
|
||||||
LogDriver: awslogs
|
|
||||||
Options:
|
|
||||||
awslogs-group: !Ref ServiceName
|
|
||||||
awslogs-region: !Ref 'AWS::Region'
|
|
||||||
awslogs-stream-prefix: !Ref ServiceName
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
id: dabb0116-abe0-48a6-a8af-cf9111c879a5
|
|
||||||
DependsOn:
|
|
||||||
- LogGroup
|
|
||||||
Metadata:
|
|
||||||
'AWS::CloudFormation::Designer':
|
|
||||||
dabb0116-abe0-48a6-a8af-cf9111c879a5:
|
|
||||||
size:
|
|
||||||
width: 60
|
|
||||||
height: 60
|
|
||||||
position:
|
|
||||||
x: 270
|
|
||||||
'y': 90
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
dependson:
|
|
||||||
- aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
c6f18447-b879-4696-8873-f981b2cedd2b:
|
|
||||||
size:
|
|
||||||
width: 60
|
|
||||||
height: 60
|
|
||||||
position:
|
|
||||||
x: 270
|
|
||||||
'y': 210
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
7f809e91-9e5d-4678-98c1-c5085956c480:
|
|
||||||
size:
|
|
||||||
width: 60
|
|
||||||
height: 60
|
|
||||||
position:
|
|
||||||
x: 60
|
|
||||||
'y': 300
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
dependson:
|
|
||||||
- aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
- c6f18447-b879-4696-8873-f981b2cedd2b
|
|
||||||
aece53ae-b82d-4267-bc16-ed964b05db27:
|
|
||||||
size:
|
|
||||||
width: 150
|
|
||||||
height: 150
|
|
||||||
position:
|
|
||||||
x: 60
|
|
||||||
'y': 90
|
|
||||||
z: 1
|
|
||||||
embeds: []
|
|
||||||
4d2da56c-3643-46b8-aaee-e46e19f95fcc:
|
|
||||||
source:
|
|
||||||
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
|
||||||
target:
|
|
||||||
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
z: 11
|
|
||||||
14eb957b-f094-4653-93c4-77b2f851953c:
|
|
||||||
source:
|
|
||||||
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
|
||||||
target:
|
|
||||||
id: c6f18447-b879-4696-8873-f981b2cedd2b
|
|
||||||
z: 12
|
|
||||||
85c57444-e5bb-4230-bc85-e545cd4558f6:
|
|
||||||
source:
|
|
||||||
id: dabb0116-abe0-48a6-a8af-cf9111c879a5
|
|
||||||
target:
|
|
||||||
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
|
||||||
z: 13
|
|
||||||
|
|
@ -0,0 +1,160 @@
|
||||||
|
export class TaskDefinitionFormation {
|
||||||
|
public static readonly formation: string = ` AWSTemplateFormatVersion: 2010-09-09
|
||||||
|
Description: >-
|
||||||
|
AWS Fargate cluster that can span public and private subnets. Supports public
|
||||||
|
facing load balancers, private internal load balancers, and both internal and
|
||||||
|
external service discovery namespaces.
|
||||||
|
Parameters:
|
||||||
|
EnvironmentName:
|
||||||
|
Type: String
|
||||||
|
Default: development
|
||||||
|
Description: 'Your deployment environment: DEV, QA , PROD'
|
||||||
|
ServiceName:
|
||||||
|
Type: String
|
||||||
|
Default: example
|
||||||
|
Description: A name for the service
|
||||||
|
ImageUrl:
|
||||||
|
Type: String
|
||||||
|
Default: nginx
|
||||||
|
Description: >-
|
||||||
|
The url of a docker image that contains the application process that will
|
||||||
|
handle the traffic for this service
|
||||||
|
ContainerPort:
|
||||||
|
Type: Number
|
||||||
|
Default: 80
|
||||||
|
Description: What port number the application inside the docker container is binding to
|
||||||
|
ContainerCpu:
|
||||||
|
Type: Number
|
||||||
|
Default: 1024
|
||||||
|
Description: How much CPU to give the container. 1024 is 1 CPU
|
||||||
|
ContainerMemory:
|
||||||
|
Type: Number
|
||||||
|
Default: 2048
|
||||||
|
Description: How much memory in megabytes to give the container
|
||||||
|
BUILDGUID:
|
||||||
|
Type: String
|
||||||
|
Default: ''
|
||||||
|
Command:
|
||||||
|
Type: String
|
||||||
|
Default: 'ls'
|
||||||
|
EntryPoint:
|
||||||
|
Type: String
|
||||||
|
Default: '/bin/sh'
|
||||||
|
WorkingDirectory:
|
||||||
|
Type: String
|
||||||
|
Default: '/efsdata/'
|
||||||
|
Role:
|
||||||
|
Type: String
|
||||||
|
Default: ''
|
||||||
|
Description: >-
|
||||||
|
(Optional) An IAM role to give the service's containers if the code within
|
||||||
|
needs to access other AWS resources like S3 buckets, DynamoDB tables, etc
|
||||||
|
EFSMountDirectory:
|
||||||
|
Type: String
|
||||||
|
Default: '/efsdata'
|
||||||
|
# template secrets p1 - input
|
||||||
|
Mappings:
|
||||||
|
SubnetConfig:
|
||||||
|
VPC:
|
||||||
|
CIDR: 10.0.0.0/16
|
||||||
|
PublicOne:
|
||||||
|
CIDR: 10.0.0.0/24
|
||||||
|
PublicTwo:
|
||||||
|
CIDR: 10.0.1.0/24
|
||||||
|
Conditions:
|
||||||
|
HasCustomRole: !Not
|
||||||
|
- !Equals
|
||||||
|
- Ref: Role
|
||||||
|
- ''
|
||||||
|
Resources:
|
||||||
|
LogGroup:
|
||||||
|
Type: 'AWS::Logs::LogGroup'
|
||||||
|
Properties:
|
||||||
|
LogGroupName: !Ref ServiceName
|
||||||
|
Metadata:
|
||||||
|
'AWS::CloudFormation::Designer':
|
||||||
|
id: aece53ae-b82d-4267-bc16-ed964b05db27
|
||||||
|
SubscriptionFilter:
|
||||||
|
Type: 'AWS::Logs::SubscriptionFilter'
|
||||||
|
Properties:
|
||||||
|
FilterPattern: ''
|
||||||
|
RoleArn:
|
||||||
|
'Fn::ImportValue': !Sub '${'${EnvironmentName}'}:CloudWatchIAMRole'
|
||||||
|
LogGroupName: !Ref ServiceName
|
||||||
|
DestinationArn:
|
||||||
|
'Fn::GetAtt':
|
||||||
|
- KinesisStream
|
||||||
|
- Arn
|
||||||
|
Metadata:
|
||||||
|
'AWS::CloudFormation::Designer':
|
||||||
|
id: 7f809e91-9e5d-4678-98c1-c5085956c480
|
||||||
|
DependsOn:
|
||||||
|
- LogGroup
|
||||||
|
- KinesisStream
|
||||||
|
KinesisStream:
|
||||||
|
Type: 'AWS::Kinesis::Stream'
|
||||||
|
Properties:
|
||||||
|
Name: !Ref ServiceName
|
||||||
|
ShardCount: 1
|
||||||
|
Metadata:
|
||||||
|
'AWS::CloudFormation::Designer':
|
||||||
|
id: c6f18447-b879-4696-8873-f981b2cedd2b
|
||||||
|
|
||||||
|
# template secrets p2 - secret
|
||||||
|
|
||||||
|
TaskDefinition:
|
||||||
|
Type: 'AWS::ECS::TaskDefinition'
|
||||||
|
Properties:
|
||||||
|
Family: !Ref ServiceName
|
||||||
|
Cpu: !Ref ContainerCpu
|
||||||
|
Memory: !Ref ContainerMemory
|
||||||
|
NetworkMode: awsvpc
|
||||||
|
Volumes:
|
||||||
|
- Name: efs-data
|
||||||
|
EFSVolumeConfiguration:
|
||||||
|
FilesystemId:
|
||||||
|
'Fn::ImportValue': !Sub '${'${EnvironmentName}'}:EfsFileStorageId'
|
||||||
|
TransitEncryption: ENABLED
|
||||||
|
RequiresCompatibilities:
|
||||||
|
- FARGATE
|
||||||
|
ExecutionRoleArn:
|
||||||
|
'Fn::ImportValue': !Sub '${'${EnvironmentName}'}:ECSTaskExecutionRole'
|
||||||
|
TaskRoleArn:
|
||||||
|
'Fn::If':
|
||||||
|
- HasCustomRole
|
||||||
|
- !Ref Role
|
||||||
|
- !Ref 'AWS::NoValue'
|
||||||
|
ContainerDefinitions:
|
||||||
|
- Name: !Ref ServiceName
|
||||||
|
Cpu: !Ref ContainerCpu
|
||||||
|
Memory: !Ref ContainerMemory
|
||||||
|
Image: !Ref ImageUrl
|
||||||
|
EntryPoint:
|
||||||
|
Fn::Split:
|
||||||
|
- ','
|
||||||
|
- !Ref EntryPoint
|
||||||
|
Command:
|
||||||
|
Fn::Split:
|
||||||
|
- ','
|
||||||
|
- !Ref Command
|
||||||
|
WorkingDirectory: !Ref WorkingDirectory
|
||||||
|
Environment:
|
||||||
|
- Name: ALLOW_EMPTY_PASSWORD
|
||||||
|
Value: 'yes'
|
||||||
|
# template - env vars
|
||||||
|
MountPoints:
|
||||||
|
- SourceVolume: efs-data
|
||||||
|
ContainerPath: !Ref EFSMountDirectory
|
||||||
|
ReadOnly: false
|
||||||
|
Secrets:
|
||||||
|
# template secrets p3 - container def
|
||||||
|
LogConfiguration:
|
||||||
|
LogDriver: awslogs
|
||||||
|
Options:
|
||||||
|
awslogs-group: !Ref ServiceName
|
||||||
|
awslogs-region: !Ref 'AWS::Region'
|
||||||
|
awslogs-stream-prefix: !Ref ServiceName
|
||||||
|
DependsOn:
|
||||||
|
- LogGroup
|
||||||
|
`;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue