【发布时间】:2019-08-27 14:00:45
【问题描述】:
当我使用以下方式部署无服务器 API 时:
serverless deploy
创建了 lambda 层,但是当我运行该函数时,出现此错误:
"Cannot find module 'request'"
但如果我通过控制台手动上传 .zip 文件(与我部署时上传的完全相同的文件),它可以正常工作。
有人知道为什么会这样吗?
environment:
SLS_DEBUG: "*"
provider:
name: aws
runtime: nodejs8.10
stage: ${opt:api-type, 'uat'}-${opt:api, 'payment'}
region: ca-central-1
timeout: 30
memorySize: 128
role: ${file(config/prod.env.json):ROLE}
vpc:
securityGroupIds:
- ${file(config/prod.env.json):SECURITY_GROUP}
subnetIds:
- ${file(config/prod.env.json):SUBNET}
apiGateway:
apiKeySourceType: HEADER
apiKeys:
- ${file(config/${opt:api-type, 'uat'}.env.json):${opt:api, "payment"}-APIKEY}
functions:
- '${file(src/handlers/${opt:api, "payment"}.serverless.yml)}'
package:
# individually: true
exclude:
- node_modules/**
- nodejs/**
plugins:
- serverless-offline
- serverless-plugin-warmup
- serverless-content-encoding
custom:
contentEncoding:
minimumCompressionSize: 0 # Minimum body size required for compression in bytes
layers:
nodejs:
package:
artifact: nodejs.zip
compatibleRuntimes:
- nodejs8.10
allowedAccounts:
- "*"
这就是我的无服务器 yaml 脚本的样子。
【问题讨论】:
标签: aws-lambda serverless-framework aws-serverless