Лямбда: значение свойства Layers должно иметь тип List of String. - PullRequest
1 голос
/ 29 мая 2020

Я начинаю пытаться написать лямбда-функцию с помощью узла и кукловода. Я использую бессерверную структуру

. Я пытался следовать https://codissimo.sinumo.tech/2019/12/27/serverless-puppeteer-with-aws-lambda-layers-and-node-js/, чтобы использовать подготовленный chrome в https://github.com/shelfio/chrome-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

Как я могу это исправить?

Изменить:

Теперь получается:

Так что, думаю, в будущем я буду использовать такой инструмент, как 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).

Есть идеи?

1 Ответ

1 голос
/ 30 мая 2020

В вашем слое 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"
      }
    ]
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...