cloudFormation.yaml
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "An AWS Lambda Function to resize images automatically with API Gateway and S3 for imagemagick tasks. When an image is called on AWS S3 bucket, this package will resize it and put to S3.",
"Resources": {
"ServerlessDeploymentBucket": {
"Type": "AWS::S3::Bucket"
},
"ImageprocessLogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "/aws/lambda/resizeS3Image"
}
},
"IamRoleLambdaExecution": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Policies": [
{
"PolicyName": {
"Fn::Join": [
"-",
[
"development",
"resizeS3Image",
"lambda"
]
]
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream"
],
"Resource": [
{
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/resizeS3Image-development-imageprocess:*"
}
]
},
{
"Effect": "Allow",
"Action": [
"logs:PutLogEvents"
],
"Resource": [
{
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/resizeS3Image-development-imageprocess:*:*"
}
]
},
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": "*"
}
]
}
}
],
"Path": "/",
"RoleName": {
"Fn::Join": [
"-",
[
"resizeS3Image",
"development",
"eu-west-1",
"lambdaRole"
]
]
}
}
},
"ImageprocessLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"S3Key": "serverless/resizeS3Image/development/1537807591540-2018-09-24T16:46:31.540Z/resizeS3Image.zip"
},
"FunctionName": "resizeS3Image",
"Handler": "build/handler.imageprocess",
"MemorySize": 1024,
"Role": {
"Fn::GetAtt": [
"IamRoleLambdaExecution",
"Arn"
]
},
"Runtime": "nodejs8.10",
"Timeout": 5,
"Environment": {
"Variables": {
"BUCKET": "<BUCKET>",
"URL": "<URL>"
}
}
},
"DependsOn": [
"ImageprocessLogGroup",
"IamRoleLambdaExecution"
]
},
"ImageprocessLambdaVersionpOamLEteDXnrsUssXms0he9m8Gr8yzLjWHFcseTUA8": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "ImageprocessLambdaFunction"
},
"CodeSha256": "1xM4jZ6U4FqQb340JJ6ubQcMAihrJcDOH/Bp09PRFBs="
}
}
},
"Outputs": {
"ServerlessDeploymentBucketName": {
"Value": {
"Ref": "ServerlessDeploymentBucket"
}
},
"ImageprocessLambdaFunctionQualifiedArn": {
"Description": "Current Lambda function version",
"Value": {
"Ref": "ImageprocessLambdaVersionpOamLEteDXnrsUssXms0he9m8Gr8yzLjWHFcseTUA8"
}
}
}
}