Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (63 sloc) 2.41 KB
AWSTemplateFormatVersion: "2010-09-09"
Description:
"ECS cluster settings for docker_rec_radiko with Fargate"
Parameters:
ProjectName:
Default: docker_rec_radiko_with_fargate
Type: String
ECSClusterName:
Default: ecs-cluster
Type: String
SSMECSSubnet:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Subnet>
Default: "/docker_rec_radiko_with_fargate/SSMSubnet"
SSMECSSecurityGroup:
Type: AWS::SSM::Parameter::Value<AWS::EC2::SecurityGroup>
Default: "/docker_rec_radiko_with_fargate/SSMSecurityGroup"
SSMFargateLauncherRole:
Type: AWS::SSM::Parameter::Value<String>
Default: "/docker_rec_radiko_with_fargate/SSMFargateLauncherRole"
Resources:
ECSCluster:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-cluster.html
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Sub "${ProjectName}-${ECSClusterName}"
FargateLauncher:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html
Type: AWS::Lambda::Function
Properties:
Environment:
Variables:
CLUSTER_NAME: !Ref ECSCluster
SUBNETS: !Ref SSMECSSubnet
SECURITY_GROUPS: !Ref SSMECSSecurityGroup
FunctionName: !Sub "${ProjectName}-FargateLauncher"
Handler: index.handler
Role: !Ref SSMFargateLauncherRole
Runtime: python3.7
Code:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html
ZipFile: |
from os import getenv
from boto3 import client
ecs = client('ecs')
def handler(event, context):
ecs.run_task(
cluster=getenv('CLUSTER_NAME'),
launchType='FARGATE',
taskDefinition=event.get('taskDefinition'),
count=1,
platformVersion='LATEST',
networkConfiguration={'awsvpcConfiguration': {
'subnets': getenv('SUBNETS').split(','),
'securityGroups': getenv('SECURITY_GROUPS').split(','),
'assignPublicIp': 'ENABLED'
}})
SSMFargateLauncher:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-parameter.html
Type: AWS::SSM::Parameter
Properties:
Name: !Sub "/${ProjectName}/SSMFargateLauncher"
Type: String
Value: !GetAtt FargateLauncher.Arn
You can’t perform that action at this time.