Thanks in advance!
So I have created this Cloudformation template below and have a circular dependency error.. I know what is causing the error, but cannot think of a solution for what I'm trying to achieve..
Which is;
Create a lambda function that has a two environment variables for two buckets I need to use in the functions code
Create two s3 buckets, one for a file input and one for a file output
Create a trigger that calls the lambda function when an object is added to the 1st bucket
Here is my code:
"lambda": {
"Type": "AWS::Lambda::Function",
"DependsOn": [
"s3accessrole",
"s3rolepolicies",
"bucket1"
],
"Properties": {
"Code": {
"S3Bucket": "resource-bucket",
"S3Key": "filepath/function.zip"
},
"Role": {
"Fn::GetAtt": [
"s3accessrole",
"Arn"
]
},
"Timeout": 60,
"Handler": "function.handler",
"Runtime": "nodejs6.10",
"MemorySize": 1024,
"Environment": {
"Variables": {
"bucket1": {
"Ref": "bucket1"
},
"bucket2": {
"Ref": "bucket2"
}
}
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
},
"bucket1": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "Private",
"LifecycleConfiguration": {
"Rules": [
{
"ExpirationInDays": "1",
"Id": "delete images/",
"Status": "Enabled"
}
]
},
"VersioningConfiguration": {
"Status": "Suspended"
},
"NotificationConfiguration": {
"LambdaConfigurations": [
{
"Event": "s3:ObjectCreated:*",
"Function": {
"Ref": "lambda"
}
}
]
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
},
"lambdaperm": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "lambda"
},
"Principal": "s3.amazonaws.com",
"SourceAccount": {
"Ref": "AWS::AccountId"
},
"SourceArn": {
"Fn::Join": [
":",
[
"arn",
"aws",
"s3",
"",
"",
{
"Ref": "bucket1"
}
]
]
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
},
"bucket2": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "Private",
"LifecycleConfiguration": {
"Rules": [
{
"ExpirationInDays": "1",
"Id": "delete images/",
"Status": "Enabled"
}
]
},
"VersioningConfiguration": {
"Status": "Suspended"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
}