兰姆达。Layers属性的值必须是List of String的类型。

问题描述 投票:1回答:1

我开始尝试用node和puppeteer写一个lambda函数。我使用的是无服务器框架

我一直在努力遵循 https:/codissimo.sinumo.tech20191227serverless-puppeteer-with-aws-lambda-layers-and-node-js。 以利用提供的chrome在 https:/github.comshelfiochrome-aws-lambda-layer。 . 我的函数在本机上工作得很正常。

我的Yaml文件包含。

provider:
  name: aws
  runtime: nodejs12.x
  region: us-east-1
  # here we put the layers we want to use
  layers:
    # Google Chrome for AWS Lambda as a layer
    # Make sure you use the latest version depending on the region
    # https://github.com/shelfio/chrome-aws-lambda-layer
    - arn:us-east-1: arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10

当我运行时:

$ serverless deploy
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Installing dependencies for custom CloudFormation resources...
Serverless: Safeguards Processing...
Serverless: Safeguards Results:

Summary --------------------------------------------------

passed - no-secret-env-vars
passed - allowed-regions
passed - framework-version
warned - require-cfn-role
passed - no-unsafe-wildcard-iam-permissions
passed - allowed-stages
passed - allowed-runtimes

Details --------------------------------------------------

1) Warned - no cfnRole set
    details: http://slss.io/sg-require-cfn-role
    Require the cfnRole option, which specifies a particular role for CloudFormation to assume while deploying.


Serverless: Safeguards Summary: 6 passed, 1 warnings, 0 errors
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service thelandnow.zip file to S3 (43.66 MB)...
Serverless: Uploading custom CloudFormation resources...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.......
Serverless: Operation failed!
Serverless: View the full error output: https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stack/detail?stackId=arn%3Aaws%3Acloudformation%3Aus-east-1%3A155754363046%3Astack%2Fsellthelandnow-dev%2F943f00e0-9d21-11ea-a8a3-12498e67507f
Serverless: Publishing service to the Serverless Dashboard...
Serverless: Successfully published your service to the Serverless Dashboard: https://dashboard.serverless.com/tenants/myaccount/applications/seller/services/thelandnow/stage/dev/region/us-east-1

Serverless Error ---------------------------------------

An error occurred: MainLambdaFunction - Value of property Layers must be of type List of String.

Get Support --------------------------------------------
    Docs:          docs.serverless.com
    Bugs:          github.com/serverless/serverless/issues
    Issues:        forum.serverless.com

Your Environment Information ---------------------------
    Operating System:          win32
    Node Version:              11.5.0
    Framework Version:         1.70.1
    Plugin Version:            3.6.11
    SDK Version:               2.3.0
    Components Version:        2.30.10

我怎样才能解决这个问题?

编辑:我的Yaml文件包含:当我运行时:如何解决这个问题?

现在得到的是:

所以我想以后我会用一个工具,比如说 https:/www.convertjson.comyaml-to-json.htm. 谢谢你,我改成了 我改成了:

layers:
  - arn:us-east-1:arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10

现在我看到了。

 An error occurred: MainLambdaFunction - 1 validation error detected: Value '[arn:us-east-1:arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10]' at 'layers' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 140, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: (arn:[a-zA-Z0-9-]+:lambda:[a-zA-Z0-9-]+:\d{12}:layer:[a-zA-Z0-9-_]+:[0-9]+)|(arn:[a-zA-Z0-9-]+:lambda:::awslayer:[a-zA-Z0-9-_]+)] (Service: AWSLambdaInternal; Status Code: 400; Error Code: ValidationException; Request ID: a5fae73b-67b5-4910-8020-c283673e55f2).

有什么想法吗?

node.js google-chrome aws-lambda serverless-framework
1个回答
1
投票

你的层ARN里有个空格。

你的配置在YAML:

provider:
  name: aws
  runtime: nodejs12.x
  region: us-east-1
  # here we put the layers we want to use
  layers:
    # Google Chrome for AWS Lambda as a layer
    # Make sure you use the latest version depending on the region
    # https://github.com/shelfio/chrome-aws-lambda-layer
    - arn:us-east-1: arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10

...在JSON中看起来是这样的 -- 在这里变得更加明显。

{
  "provider": {
    "name": "aws",
    "runtime": "nodejs12.x",
    "region": "us-east-1",
    "layers": [
      {
        "arn:us-east-1": "arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10"
      }
    ]
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.