Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (102 sloc) 3.62 KB
AWSTemplateFormatVersion: "2010-09-09"
Description:
"ECS task and CloudWatch event settings for docker_rec_radiko with Fargate"
Parameters:
ECSCommand:
Type: String
Default: "TBS, 1, tbs_test"
ECSTaskSchedulerPattern:
Type: String
Default: "0/3 * * * ? *"
ECSTaskName:
Type: String
Default: tbs_test_task
ImageName:
Type: String
Default: "XXXXXXXXXXXX.dkr.ecr.ap-northeast-1.amazonaws.com/docker_rec_radiko:latest"
S3BucketName:
Type: String
Default: "changeme"
ECSTaskCpu:
Type: String
Default: 256
ECSTaskMemory:
Type: String
Default: 512
ProjectName:
Type: String
Default: docker_rec_radiko_with_fargate
LambdaTaskSchedulerName:
Type: String
Default: "lambda-scheduler"
SSMFargateLauncher:
Type: AWS::SSM::Parameter::Value<String>
Default: "/docker_rec_radiko_with_fargate/SSMFargateLauncher"
SSMECSTaskExecutorRole:
Type: AWS::SSM::Parameter::Value<String>
Default: "/docker_rec_radiko_with_fargate/SSMECSTaskExecutorRole"
ECSTaskWorkingDirectory:
Type: String
Default: "/recorded"
Resources:
ECSTaskDefinition:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-taskdefinition.html
Type: AWS::ECS::TaskDefinition
Properties:
Cpu: !Ref ECSTaskCpu
ExecutionRoleArn: !Ref SSMECSTaskExecutorRole
TaskRoleArn: !Ref SSMECSTaskExecutorRole
Memory: !Ref ECSTaskMemory
NetworkMode: awsvpc
RequiresCompatibilities:
- FARGATE
ContainerDefinitions:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-taskdefinition-containerdefinitions.html
-
Command: !Split [",", !Sub "run_fargate.sh, ${ECSCommand}"]
Cpu: !Ref ECSTaskCpu
Environment:
-
Name: BucketName
Value: !Ref S3BucketName
Image: !Ref ImageName
LogConfiguration:
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html
LogDriver: awslogs
Options:
awslogs-group: !Ref ECSLogGroup
awslogs-region: !Ref "AWS::Region"
awslogs-stream-prefix: !Ref ProjectName
Memory: !Ref ECSTaskMemory
Name: !Sub "${ProjectName}-${ECSTaskName}-container"
WorkingDirectory: !Ref ECSTaskWorkingDirectory
ECSLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/ecs/logs/${ProjectName}-${ECSTaskName}-log-group"
LambdaTaskScheduler:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html
Type: AWS::Events::Rule
Properties:
# https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/events/ScheduledEvents.html
Description: !Sub "$${ECSTaskName} in {ProjectName}"
Name: !Sub "${ProjectName}-${ECSTaskName}-${LambdaTaskSchedulerName}"
ScheduleExpression: !Sub "cron(${ECSTaskSchedulerPattern})"
State: ENABLED
Targets:
# https://docs.aws.amazon.com/AmazonCloudWatchEvents/latest/APIReference/API_PutTargets.html
-
Id: 1
Arn: !Ref SSMFargateLauncher
Input: !Sub |
{
"taskDefinition": "${ECSTaskDefinition}"
}
LambdaPermission:
# https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-permission.html
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref SSMFargateLauncher
Action: "lambda:InvokeFunction"
Principal: "events.amazonaws.com"
SourceArn: !GetAtt LambdaTaskScheduler.Arn
You can’t perform that action at this time.