简体   繁体   English

无服务器错误 - CloudFormation 模板无效 - 部署期间

[英]Serverless error - The CloudFormation template is invalid - during deployment

When deploying lambdas with serverless, the following error occurs:使用无服务器部署 lambdas 时,出现以下错误:

The CloudFormation template is invalid: Template format error: Output ServerlessDeploymentBucketName is malformed. CloudFormation 模板无效:模板格式错误:输出 ServerlessDeploymentBucketName 格式错误。 The Name field of every Export member must be specified and consist only of alphanumeric characters, colons, or hyphens.必须指定每个导出成员的名称字段,并且仅包含字母数字字符、冒号或连字符。

I don't understand what the problem is.我不明白问题是什么。

Serverless config file:无服务器配置文件:

service: lambdas-${opt:region}

frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs12.x
  memorySize: 512
  timeout: 10
  lambdaHashingVersion: 20201221
  region: ${opt:region}
  stackName: lambdas-${opt:region}
  logRetentionInDays: 14
  deploymentBucket:
    name: lambdas-${opt:region}

plugins:
  - serverless-deployment-bucket

functions:
  function1:
    handler: function1/index.handler
    name: function1-${opt:stage}
    description: This function should call specific API on Backend server
    events:
      - schedule: cron(0 0 * * ? *)
    environment:
      ENV: ${opt:stage}
  function2:
    handler: function2/index.handler
    name: function2-${opt:stage}
    description: Function should be triggered by invocation from backend.
    environment:
      ENV: ${opt:stage}

Most likely your stage name contains an illegal character.很可能您的艺名包含非法字符。 Serverless auto-generates a name for your s3 bucket based on your stage name. Serverless 会根据您的阶段名称为您的 s3 存储桶自动生成一个名称。 If you look at the generated template file you will see the full export, which will look something like the following:如果您查看生成的模板文件,您将看到完整的导出,如下所示:

 "ServerlessDeploymentBucketName": { "Value": "api-deployment", "Export": { "Name": "sls-api_stage-ServerlessDeploymentBucketName" } },

The way around this (assuming you don't want to change your stage name) is to explicitly set the output by adding something like this to your serverless config (in this case the illegal character was the underscore)解决此问题的方法(假设您不想更改舞台名称)是通过向无服务器配置添加类似内容来显式设置输出(在这种情况下,非法字符是下划线)

 resources: { Outputs: { ServerlessDeploymentBucketName: { Export: { Name: `sls-${stageKey.replace('api_', 'api-')}-ServerlessDeploymentBucketName` } } } }

Unfortunately this has to be done for every export... It is a better option to update your stage name to not include illegal characters不幸的是,每次导出都必须这样做......更新您的舞台名称以不包含非法字符是更好的选择

I ran into this same problem.我遇到了同样的问题。

In the serverless.yml I changed service that I had it as lambda_function and put it as lambdaFunctionserverless.yml我改变了服务,我有它作为lambda_function并把它作为lambdaFunction

The error was solved and it deployed correctly.错误已解决并正确部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM