【问题标题】:Why S3 bucket is not getting created though it is mentioned in SAM template?尽管 SAM 模板中提到了 S3 存储桶,但为什么没有创建它?
【发布时间】:2021-12-05 11:21:55
【问题描述】:

我正在尝试在 S3 存储桶中创建一个带有函数代码的 lambda 函数。下面是我的模板。 此模板创建 lambda,但不创建提到的 S3 存储桶。我正在寻求帮助以通过此模板创建 S3 存储桶。

Resources:
  ProducerLambda:
    Type: 'AWS::Serverless::Function'
    Properties:
      FunctionName: !Sub '${ApplicationId}-${env}-Producer-Lambda-${AWS::AccountId}-${AWS::Region}'
      Handler: index.handler
      Runtime: nodejs14.x
      CodeUri:
        Bucket: s3bucket   
        Key: s3bucketref.zip
      Role: 'arn:aws:iam::${AWS::AccountId}:role/Producer-lambda-trigger-role' 
      VpcConfig:
        SecurityGroupIds: !Ref SecurityGroup
        SubnetIds: !Ref VPCSubnetId
      Environment:
        Variables:
          Region: !Sub '${AWS::Region}'

【问题讨论】:

  • bucket 中有 zip 文件吗?

标签: amazon-web-services amazon-s3 amazon-cloudformation aws-sam


【解决方案1】:

CodeUri 用于指定函数代码的路径 - 这可以是 Amazon S3 URI、本地文件夹的路径或 FunctionCode 对象。

它们不用于创建 S3 存储桶。

如果s3bucket/s3bucketref.zip不存在打包函数,则需要自己创建bucket并上传包。

或者,使用sam build 将为您构建 Lambda,然后sam deploy 将自动为您创建一个 S3 存储桶:

通过 AWS CloudFormation 部署 AWS Lambda 函数需要用于 Lambda 部署包的 Amazon Simple Storage Service (Amazon S3) 存储桶。 AWS SAM CLI 为您创建和管理此 Amazon S3 存储桶。

后者管理起来要简单得多。

【讨论】:

    猜你喜欢
    • 2020-03-29
    • 2020-08-11
    • 2020-01-17
    • 2021-03-24
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 2019-05-06
    • 2021-08-14
    相关资源
    最近更新 更多