简体   繁体   English

AWS Cloudformation Lambda S3 - 循环依赖

[英]AWS Cloudformation Lambda S3 - Circular Dependency

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.. 所以我在下面创建了这个Cloudformation模板并且有一个循环依赖性错误..我知道导致错误的是什么,但是我想不出解决方案我想要实现的目标。

Which is; 这是;

  • Create a lambda function that has a two environment variables for two buckets I need to use in the functions code 创建一个lambda函数,它有两个我需要在函数代码中使用的桶的环境变量

  • Create two s3 buckets, one for a file input and one for a file output 创建两个s3存储桶,一个用于文件输入,另一个用于文件输出

  • Create a trigger that calls the lambda function when an object is added to the 1st bucket 创建一个触发器,在将对象添加到第一个存储桶时调用lambda函数

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"
                }
            }
        }

来自lambda函数中第一个存储桶的传入事件包含用于该存储桶的名称,因此我不需要创建环境变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM