提前致谢!
所以我在下面创建了这个Cloudformation模板并且有一个循环依赖性错误..我知道导致错误的是什么,但是想不出我正在努力实现的解决方案..
是哪个;
创建一个lambda函数,它有两个我需要在函数代码中使用的桶的环境变量
创建两个s3存储桶,一个用于文件输入,另一个用于文件输出
创建一个触发器,在将对象添加到第一个存储桶时调用lambda函数
这是我的代码:
"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"
}
}
}
答案 0 :(得分:0)
lambda函数中第一个存储桶的传入事件包含用于该存储桶的名称,因此我不需要创建环境变量。