【发布时间】:2020-10-28 23:48:29
【问题描述】:
我读到 SAM 现在支持构建层,并遵循here 中提到的指示。但是,当我尝试使用 sam build samDeployLayer 在本地构建层时,我遇到了构建错误
Build Failed
Error: NodejsNpmBuilder:NpmPack - NPM Failed: npm ERR! code ENOLOCAL
npm ERR! Could not install from "E:\Development\sam-deploy\src\sam-deploy-layer" as it does not contain a package.json file.
这是我的模板文件:
AWSTemplateFormatVersion: 2010-09-09
Description: >-
sam-deploy
Transform:
- AWS::Serverless-2016-10-31
Resources:
samDeploy:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/sam-deploy
Handler: index.handler
Runtime: nodejs12.x
MemorySize: 128
Timeout: 100
Description: A Lambda function that returns a static string.
FunctionName: "sam-deploy"
Layers:
- !Ref samDeployLayer
Policies:
# Give Lambda basic execution Permission to the helloFromLambda
- AWSLambdaBasicExecutionRole
samDeployLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: sam-deploy-layer
ContentUri: src/sam-deploy-layer
CompatibleRuntimes:
- nodejs12.x
Metadata:
BuildMethod: nodejs12.x
根据构建层的要求,我已经包含了CompatibleRuntimes 和Metadata 属性。此层的package.json 位于src/sam-deploy-layer/nodejs,这是 nodeJS 运行时所需的,我使用的是 SAM CLI 版本 0.53.0。我做错了什么?
【问题讨论】:
-
你应该有一个 package.json 用于两个节点项目(samDeploy 和 samDeployLayer)。此文件应位于
src/sam-deploy和src/sam-deploy-layer位置(分别)否则更新您的CodeUri和/或ContentUri值。
标签: node.js amazon-web-services aws-lambda yaml aws-sam