Skip to content

Instantly share code, notes, and snippets.

@rupakg
Created October 12, 2018 18:58
Show Gist options
  • Save rupakg/e2f32995a7648db76391ab647c4fc7e7 to your computer and use it in GitHub Desktop.
Save rupakg/e2f32995a7648db76391ab647c4fc7e7 to your computer and use it in GitHub Desktop.
AWS CF Circular Dependency Issue
AWSTemplateFormatVersion: "2010-09-09"
Outputs:
DeploymentHistoryId:
Description: "Stackery Deployment History ID"
Value: "4148"
Parameters:
StackeryEnvironmentTagName:
Default: development
Type: String
Description: "Environment Name (injected by Stackery at deployment time)"
StackeryStackTagName:
Default: sls-video-processing-with-fargate
Type: String
Description: "Stack Name (injected by Stackery at deployment time)"
DefaultVPCSubnets:
Default: "subnet-1adfb316,subnet-e823fab2,subnet-e63a3d83,subnet-82725fbe,subnet-5c3f9f70,subnet-8131aec9"
Type: "List<AWS::EC2::Subnet::Id>"
Description: "AWS account-specific default VPC subnets (injected by Stackery at deployment time)"
Description: "Video processing app with AWS Fargate using Stackery"
Resources:
functionF9A32476objectStore3B0DC7B6Permission:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:invokeFunction"
SourceAccount: { Ref: "AWS::AccountId" }
FunctionName: { Ref: functionF9A32476 }
Principal: s3.amazonaws.com
function17279F64Role:
Type: "AWS::IAM::Role"
Properties:
ManagedPolicyArns:
[
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess",
]
Policies:
[
{
PolicyName: function17279F64RolePolicy1,
PolicyDocument:
{
Statement:
[
{
Action:
["ecs:RunTask", "ecs:DescribeTasks", "ecs:StopTask"],
Resource:
[
{ Ref: dockerTask4259BAF6 },
{
"Fn::Sub": "arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:task/*",
},
],
Effect: Allow,
},
],
},
},
{
PolicyName: function17279F64RolePolicy2,
PolicyDocument:
{
Statement:
[
{
Action: ["iam:PassRole"],
Resource:
[
{ "Fn::GetAtt": dockerTask4259BAF6ExecutionRole.Arn },
{ "Fn::GetAtt": dockerTask4259BAF6TaskRole.Arn },
],
Effect: Allow,
},
],
},
},
{
PolicyName: function17279F64RolePolicy3,
PolicyDocument:
{
Statement:
[
{
Action:
[
"s3:GetObject",
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:GetObjectVersion",
"s3:PutObject",
"s3:GetLifecycleConfiguration",
"s3:PutLifecycleConfiguration",
"s3:DeleteObject",
],
Resource:
[
{
"Fn::Sub":
[
"arn:${AWS::Partition}:s3:::${bucketName}",
{ bucketName: { Ref: objectStore3B0DC7B6 } },
],
},
{
"Fn::Sub":
[
"arn:${AWS::Partition}:s3:::${bucketName}/*",
{ bucketName: { Ref: objectStore3B0DC7B6 } },
],
},
],
Effect: Allow,
},
],
},
},
{
PolicyName: function17279F64RolePolicy4,
PolicyDocument:
{
Statement:
[
{
Action:
[
"s3:GetObject",
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:GetObjectVersion",
"s3:PutObject",
"s3:GetLifecycleConfiguration",
"s3:PutLifecycleConfiguration",
"s3:DeleteObject",
],
Resource:
[
{
"Fn::Sub":
[
"arn:${AWS::Partition}:s3:::${bucketName}",
{ bucketName: { Ref: objectStore6A12D98C } },
],
},
{
"Fn::Sub":
[
"arn:${AWS::Partition}:s3:::${bucketName}/*",
{ bucketName: { Ref: objectStore6A12D98C } },
],
},
],
Effect: Allow,
},
],
},
},
]
AssumeRolePolicyDocument:
{
Version: "2012-10-17",
Statement:
[
{
Action: ["sts:AssumeRole"],
Effect: Allow,
Principal: { Service: [lambda.amazonaws.com] },
},
],
}
DeploymentMarker4148:
Type: "AWS::CloudFormation::WaitConditionHandle"
functionF9A32476Role:
Type: "AWS::IAM::Role"
Properties:
ManagedPolicyArns:
[
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
"arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess",
]
AssumeRolePolicyDocument:
{
Version: "2012-10-17",
Statement:
[
{
Action: ["sts:AssumeRole"],
Effect: Allow,
Principal: { Service: [lambda.amazonaws.com] },
},
],
}
dockerTask4259BAF6LogGroup:
Type: "AWS::Logs::LogGroup"
Properties:
LogGroupName:
{
"Fn::Sub": "/stackery/task/${AWS::StackName}-dockerTask4259BAF6/rupakg-docker-ffmpeg-thumb-latest",
}
DependsOn:
- DeploymentMarker4148
objectStore3B0DC7B6:
Type: "AWS::S3::Bucket"
Properties:
NotificationConfiguration:
{
LambdaConfigurations:
[
{
Function: { "Fn::GetAtt": [functionF9A32476, Arn] },
Event: "s3:ObjectCreated:*",
},
{
Function: { "Fn::GetAtt": [functionF9A32476, Arn] },
Event: "s3:ObjectRemoved:*",
},
],
}
BucketName: { "Fn::Sub": "${AWS::StackName}-objectstore3b0dc7b6" }
DependsOn:
- DeploymentMarker4148
- functionF9A32476objectStore3B0DC7B6Permission
dockerTask4259BAF6ExecutionRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: { "Fn::Sub": "${AWS::StackName}-DockerTaskExecutionRole" }
Policies:
[
{
PolicyName: DownloadDockerImagesFromECR,
PolicyDocument:
{
Version: "2012-10-17",
Statement:
[
{
Action: ["logs:CreateLogStream", "logs:PutLogEvents"],
Resource:
{
"Fn::Sub": "arn:aws:logs:*:*:log-group:/stackery/task/${AWS::StackName}-*",
},
Effect: Allow,
},
{
Action:
[
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
],
Resource: "*",
Effect: Allow,
},
],
},
},
]
AssumeRolePolicyDocument:
{
Version: "2012-10-17",
Statement:
{
Action: "sts:AssumeRole",
Effect: Allow,
Principal: { Service: ecs-tasks.amazonaws.com },
},
}
DependsOn:
- DeploymentMarker4148
functionF9A32476:
Type: "AWS::Lambda::Function"
Properties:
TracingConfig: { Mode: Active }
Code:
{
S3Bucket: stackery-assetsbucket-48y43qp9vwya,
S3Key: deployments/249834123825422/4148/functions/functionF9A32476.zip,
}
FunctionName: { "Fn::Sub": "${AWS::StackName}-functionF9A32476" }
Tags: [{ Value: SAM, Key: "lambda:createdBy" }]
MemorySize: 512
Environment:
{
Variables:
{
STACKERY_ENTRY_POINT: index.handler,
STACKERY_NODE: '{"id":"functionF9A32476","name":"triggerOnThumbnailCreationStackery"}',
STACKERY_ERROR_OUTPUT: { "Fn::Sub": "[]" },
},
}
Handler: __stackery_entry.handler
Role: { "Fn::GetAtt": [functionF9A32476Role, Arn] }
Timeout: 30
Runtime: nodejs8.10
Description:
{
"Fn::Sub":
[
"Stackery Stack ${StackeryStackTagName} Environment ${StackeryEnvironmentTagName} Function ${ResourceName}",
{ ResourceName: triggerOnThumbnailCreationStackery },
],
}
DependsOn:
- DeploymentMarker4148
objectStore6A12D98C:
Type: "AWS::S3::Bucket"
Properties:
NotificationConfiguration:
{
LambdaConfigurations:
[
{
Function: { "Fn::GetAtt": [function17279F64, Arn] },
Event: "s3:ObjectCreated:*",
},
{
Function: { "Fn::GetAtt": [function17279F64, Arn] },
Event: "s3:ObjectRemoved:*",
},
],
}
BucketName: { "Fn::Sub": "${AWS::StackName}-objectstore6a12d98c" }
DependsOn:
- DeploymentMarker4148
- function17279F64objectStore6A12D98CPermission
dockerTask4259BAF6:
DependsOn:
- dockerTask4259BAF6LogGroup
- DeploymentMarker4148
Type: "AWS::ECS::TaskDefinition"
Properties:
ContainerDefinitions:
[
{
LogConfiguration:
{
LogDriver: awslogs,
Options:
{
awslogs-region: { Ref: "AWS::Region" },
awslogs-stream-prefix: rupakg-docker-ffmpeg-thumb-latest,
awslogs-group: { Ref: dockerTask4259BAF6LogGroup },
},
},
Environment:
[
{ Name: AWS_REGION, Value: us-east-1 },
{
Name: INPUT_VIDEO_FILE_URL,
Value: "https://s3.amazonaws.com/your-s3-bucket-name/test.mp4",
},
{
Name: OUTPUT_S3_PATH,
Value: your-s3-bucket-name/your-thumbnail-folder-name,
},
{ Name: OUTPUT_THUMBS_FILE_NAME, Value: test.png },
{ Name: POSITION_TIME_DURATION, Value: "00:01" },
{ Name: BUCKET_NAME, Value: { Ref: objectStore3B0DC7B6 } },
{
Name: BUCKET_ARN,
Value: { "Fn::GetAtt": objectStore3B0DC7B6.Arn },
},
],
Image: "rupakg/docker-ffmpeg-thumb:latest",
Name: video-to-thumb-container,
},
]
NetworkMode: awsvpc
RequiresCompatibilities: [FARGATE]
ExecutionRoleArn: { "Fn::GetAtt": dockerTask4259BAF6ExecutionRole.Arn }
Volumes: []
Memory: 512
TaskRoleArn: { "Fn::GetAtt": dockerTask4259BAF6TaskRole.Arn }
Cpu: 256
Metadata:
StackeryName: stackery-video-to-thumb-task-def
dockerTask4259BAF6TaskRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: { "Fn::Sub": "${AWS::StackName}-DockerTaskTaskRole" }
Policies:
[
{
PolicyName: StackeryPolicy,
PolicyDocument:
{
Version: "2012-10-17",
Statement:
[
{
Action:
[
"s3:GetObject",
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:GetObjectVersion",
"s3:PutObject",
"s3:GetLifecycleConfiguration",
"s3:PutLifecycleConfiguration",
],
Resource:
[
{
"Fn::Sub": "arn:${AWS::Partition}:s3:::${objectStore3B0DC7B6}",
},
{
"Fn::Sub": "arn:${AWS::Partition}:s3:::${objectStore3B0DC7B6}/*",
},
],
Effect: Allow,
},
],
},
},
]
AssumeRolePolicyDocument:
{
Version: "2012-10-17",
Statement:
{
Action: "sts:AssumeRole",
Effect: Allow,
Principal: { Service: ecs-tasks.amazonaws.com },
},
}
DependsOn:
- DeploymentMarker4148
function17279F64:
Type: "AWS::Lambda::Function"
Properties:
TracingConfig: { Mode: Active }
Code:
{
S3Bucket: stackery-assetsbucket-48y43qp9vwya,
S3Key: deployments/249834123825422/4148/functions/function17279F64.zip,
}
FunctionName: { "Fn::Sub": "${AWS::StackName}-function17279F64" }
Tags: [{ Value: SAM, Key: "lambda:createdBy" }]
MemorySize: 512
Environment:
{
Variables:
{
STACKERY_NODE: '{"id":"function17279F64","name":"triggerOnUploadVideoStackery"}',
STACKERY_ENTRY_POINT: index.handler,
STACKERY_ERROR_OUTPUT: { "Fn::Sub": "[]" },
DOCKER_TASK_ARN: { Ref: dockerTask4259BAF6 },
BUCKET_ARN_2: { "Fn::GetAtt": objectStore6A12D98C.Arn },
DOCKER_TASK_SUBNETS:
{ "Fn::Join": [",", { Ref: DefaultVPCSubnets }] },
BUCKET_NAME: { Ref: objectStore3B0DC7B6 },
BUCKET_ARN: { "Fn::GetAtt": objectStore3B0DC7B6.Arn },
BUCKET_NAME_2: { Ref: objectStore6A12D98C },
},
}
Handler: __stackery_entry.handler
Role: { "Fn::GetAtt": [function17279F64Role, Arn] }
Timeout: 30
Runtime: nodejs8.10
Description:
{
"Fn::Sub":
[
"Stackery Stack ${StackeryStackTagName} Environment ${StackeryEnvironmentTagName} Function ${ResourceName}",
{ ResourceName: triggerOnUploadVideoStackery },
],
}
DependsOn:
- DeploymentMarker4148
function17279F64objectStore6A12D98CPermission:
Type: "AWS::Lambda::Permission"
Properties:
Action: "lambda:invokeFunction"
SourceAccount: { Ref: "AWS::AccountId" }
FunctionName: { Ref: function17279F64 }
Principal: s3.amazonaws.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment