1 Answer
- Newest
- Most votes
- Most comments
0
Hello.
Make your CloudFormation template as follows.
The cause of the error was that the variable referenced by "!Ref" was not set.
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-batch-jobdefinition.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Sample template to illustrate use of existing S3 bucket as an event source for a Lambda function
Parameters:
################入力箇所
###############
BucketName:
Type: String
Description: "バケット"
Default: "Test"
EmployeeID:
Type: String
Description: "社員番号"
Default: "123456"
ProjectName:
Type: String
Description: "プロジェクト名"
Default: "TestProject"
MemSize:
Type: Number
Description: memoryサイズ(単位MB)
Default: 1024
ImageURL:
Type: String
Description: "ECRのrepositoryのpath"
TimeOutSec:
Type: Number
Description: "timeouta(単位:秒)"
Default: 1800
UlimitsName:
Type: String
Default: "nofile"
UlimitsSoft:
Type: Number
Default: 65535
UlimitsHard:
Type: Number
Default: 65535
######################################
#######################################
###
ExecutionRoleArn:
Type: String
Description: "arn"
Default: "arn:aws:iam::1234:role/awsbatch-ECSTaskExecutionRole"
VCPU:
Type: Number
Memory:
Type: Number
Default: 1024
GPU:
Type: Number
Default: 1
ShmSize:
Type: Number
Description: "shared memory mega byte(MB)"
Default: 4096
CostSharingKey:
Type: String
Default: "Cost Sharing"
CostSharingValue:
Type: String
Default: "awsbatch"
CostDetailKey:
Type: String
Default: "Cost Detail"
#cost sharingva lue
#####
#####
Resources:
ECSTaskRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Sub 'awsbatch-${EmployeeID}-${ProjectName}'
Tags:
- Key: !Ref CostSharingKey
Value: !Ref CostSharingValue
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- ecs-tasks.amazonaws.com
#lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: !Sub 'awsbatch-${EmployeeID}-${ProjectName}'
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- "s3:ListBucket"
Resource: !Sub 'arn:aws:s3:::${BucketName}'
Condition:
StringEquals:
"s3:prefix": !Sub "${EmployeeID}/${ProjectName}"
- Effect: Allow
Action:
- 's3:PutObject'
- 's3:AbortMultipartUpload'
- 's3:DeleteObject'
Resource: !Sub 'arn:aws:s3:::${BucketName}/${EmployeeID}/${ProjectName}/output/'
- Effect: Allow
Action:
- 's3:GetObject'
Resource: !Sub 'arn:aws:s3:::${BucketName}/${EmployeeID}/${ProjectName}/*'
JobDefinition:
Type: AWS::Batch::JobDefinition
Properties:
TimeOut:
AttemptDurationSeconds: !Ref TimeOutSec
Tags:
- Key: !Ref CostSharingKey
Value: !Ref CostSharingValue
- Key: !Ref CostDetailKey
Value: !Sub "${EmployeeID}-${ProjectName}"
Type: container
JobDefinitionName: !Sub "awsbatch-${EmployeeID}"
#platformは明示しなければEC2なので省略
PropagateTags: True
ExecutionRoleArn: !Ref ExecutionRoleArn
TaskRoleArn: !GetAtt ECSTaskRole.Arn # <-- ARNを取得
EcsProperties: # <-- EcsPropertiesに修正 (Eは大文字です)
TaskProperties:
- Containers:
- Command:
- echo "hoge"
- echo "hoge2"
image : !Ref ImageURL
LinuxParameters:
SharedMemorySize: !Ref ShmSize
LogConfiguration:
LogDriver: "awslogs"
ResourceRequirements:
- Type: VCPU
Value: !Ref VCPU # <-- 追加
- Type: MEMORY
Value: !Ref Memory # <-- 追加
- Type: GPU
Value: !Ref GPU
User: root
Ulimit:
HardLimit: !Ref UlimitsHard
Name: !Ref UlimitsName
SoftLimit: !Ref UlimitsSoft
