我开始尝试用node和puppeteer编写lambda函数。我正在使用无服务器框架
我一直在尝试遵循https://codissimo.sinumo.tech/2019/12/27/serverless-puppeteer-with-aws-lambda-layers-and-node-js/来利用https://github.com/shelfio/chrome-aws-lambda-layer处的预置chrome。我的功能在本地正常工作。
我的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
我该如何解决?
编辑:
现在得到:
所以我想将来我会使用类似https://www.convertjson.com/yaml-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).
有什么想法吗?
答案 0 :(得分: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"
}
]
}
}