AWS Cloudformation Lambda S3 - 循环依赖
AWS Cloudformation Lambda S3 - Circular Dependency
提前致谢!
所以我在下面创建了这个 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"
}
}
}
lambda 函数中来自第一个存储桶的传入事件包含用于该存储桶的名称,因此我不需要创建环境变量。
提前致谢!
所以我在下面创建了这个 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"
}
}
}
lambda 函数中来自第一个存储桶的传入事件包含用于该存储桶的名称,因此我不需要创建环境变量。