简体   繁体   English

aws lambda - 如果手动创建 s3 存储桶,如何使用 cloudformation 添加 s3 触发器

[英]aws lambda - How to add s3 trigger using cloudformation if the s3 bucket is created manually

I have created my s3 bucket "myBucket" manually.我已经手动创建了我的 s3 存储桶“myBucket”。

And I need a lambda function with s3 trigger.我需要一个带 s3 触发器的 lambda 函数。

    "Parameters": {
      "HandlerCodeS3Bucket": {
        "Type": "String",
        "Default": "myBucket"
      },
    },
    "Resources": {
      "uploadBannerToS3Handler": {
        "Type": "AWS::Lambda::Function",
        "Properties": {
          "FunctionName": "uploadBannerToS3",
          "Handler": "uploadBannerToS3.handler",
          "Role": {
            "Fn::ImportValue": {
              "Fn::Sub": "${RolesStack}-LambdaRoleArn"
            }
          },
          "Code": {
            "S3Bucket": {
              "Ref": "HandlerCodeS3Bucket"
            },
            "S3Key":"uploadBannerToS3.zip"
          },
          "Layers": [
            {
              "Ref": "MyLayer"
            }
          ],
          "Runtime": "nodejs12.x"
        }
      }
          ...
    }

How should I modify the code to add s3 trigger in my function.我应该如何修改代码以在我的函数中添加 s3 触发器。

Also, for development, is it more convenient if I build my s3 bucket in cloudformation also, if I will build my UAT environment in the future?另外,对于开发,如果我也在cloudformation中构建我的s3bucket是否更方便,如果我将来构建我的UAT环境?
How would developer normally do for s3 if using cloudformation?如果使用 cloudformation,开发人员通常会如何处理 s3?

If you created your bucket manually, then you can't use it in CloudFormation (CFN) the way you are trying to do.如果您手动创建了您的存储桶,则您无法按照您尝试的方式在 CloudFormation (CFN) 中使用它。 You either have to leave bucket creation and management to CFN, or if you really want, you can import existing bucket into CFN.您要么必须将存储桶的创建和管理留给 CFN,或者如果您确实需要,您可以现有的存储桶导入 CFN。

I still need to manually upload my lambda zip files to s3 manually,我仍然需要手动将我的 lambda zip 文件上传到 s3,

Yes.是的。 CFN will not upload it for you as it has no access to your local workstation. CFN 不会为您上传它,因为它无法访问您的本地工作站。 But AWS CLI has commands such as package that can make the upload process easier.但是 AWS CLI 具有诸如package 之类的命令可以使上传过程更容易。

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

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