Amazon web services 使用参数的Cloudformation LayerVersion S3Bucket

Amazon web services 使用参数的Cloudformation LayerVersion S3Bucket,amazon-web-services,aws-lambda,amazon-cloudformation,aws-lambda-layers,Amazon Web Services,Aws Lambda,Amazon Cloudformation,Aws Lambda Layers,我正在尝试使用Cloudformation打包和部署一个简单的“hello world”无服务器应用程序,该应用程序使用一个Lambda层。我遇到的问题是,我的CF模板文件中的LayerVersion部分似乎不喜欢我使用!Ref指定S3Bucket和S3Key值。我不想硬编码这些;我在文档中没有发现任何东西表明我试图做的事情行不通,但行不通:( 下面是失败的deploy命令的输出: aws cloudformation deploy --template-file out.yml --stack

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

下面是失败的
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.

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

正确属性为:

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


有趣的是,cloudformation和sam文档不同意:(@AJ.您使用的是
AWS::Serverless::LayerVersion
,而不是
AWS::LayerVersion
。我的链接是指向
AWS::Serverless::LayerVersion
的文档。
  Bucket: String
  Key: String
  Version: String
 S3Bucket: String
 S3Key: String