我读到过,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 version0.53.0。我做错了什么?
发布于 2021-04-13 08:51:00
将package.json放在src/sam-deploy-layer/下。在运行sam build之后,应该创建目录.aws-sam/build/samDeployLayer/nodejs/node_modules/。
发布于 2021-04-13 08:57:50
您应该在src/sam-deploy-layer中创建一个名为nodejs的文件夹。在这里,您可以执行npm init和npm install (在您的层中安装包)。
https://stackoverflow.com/questions/62796961
复制相似问题