【问题标题】:Cloudformation LayerVersion S3Bucket Using ParameterCloudformation LayerVersion S3Bucket 使用参数
【发布时间】:2020-10-11 16:47:15
【问题描述】:

我正在尝试使用 Cloudformation 打包和部署一个使用单个 Lambda 层的简单“hello world”无服务器应用程序。我遇到的问题是我的 CF 模板文件中的LayerVersion 部分似乎不喜欢我使用!Ref 来指定S3BucketS3Key 值的事实。我不想硬编码这些;我在文档中发现的任何内容都表明我正在尝试做的事情不起作用,但它不起作用:(

这是失败的deploy 命令的输出:

aws cloudformation deploy --template-file out.yml --stack-name cftest-lambda --parameter-overrides S3BucketNameParameter=cftest-0eddf3f0b289f2c2 S3LambdaLayerNameParameter=cftest-lambda-layer-1602434332.zip --capabilities CAPABILITY_NAMED_IAM

Waiting for changeset to be created..

Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [libs] is invalid. property Content not defined for resource of type AWS::Serverless::LayerVersion

这是完整的 CF 模板文件:

cat template.yml 
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Lambda application
Parameters: 
  S3BucketNameParameter: 
    Type: String
    Description: Bucket name for deployment artifacts
  S3LambdaLayerNameParameter:
    Type: String
    Description: Object name for lambda layer deployment artifact
Resources:
  helloworldfunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.8
      CodeUri: hello-world-with-layer/.
      Description: Hello world function to test cf using layers
      Timeout: 10
      # Function's execution role
      Policies:
        - AWSLambdaBasicExecutionRole
        - AWSLambdaReadOnlyAccess
        - AWSXrayWriteOnlyAccess
      Tracing: Active
      Layers:
        - !Ref libs
  libs:
    Type: AWS::Serverless::LayerVersion
    Properties:
      Content:
        S3Bucket: !Ref S3BucketNameParameter
        S3Key: !Ref S3LambdaLayerNameParameter
      CompatibleRuntimes:
        - python3.8
      LayerName: hello-world-lib
      Description: Dependencies for the hello-world-with-layer app.

关于如何正确处理此问题的任何建议?

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cloudformation aws-lambda-layers


    【解决方案1】:

    LayerContent正确属性是:

      Bucket: String
      Key: String
      Version: String
    

    但是,您使用的是(不同的名称):

     S3Bucket: String
     S3Key: String
    

    【讨论】:

    猜你喜欢
    • 2017-08-16
    • 1970-01-01
    • 2017-07-31
    • 2021-09-11
    • 2020-03-31
    • 2019-12-01
    • 2018-05-30
    • 1970-01-01
    • 2019-01-05
    相关资源
    最近更新 更多