Amazon web services SAM节点+;Python lambdas在一起
是否可以在同一个模板文件中同时运行Node和Python lambda,并通过CodePipeline+CodeBuild进行构建?我经常遇到的错误是:Amazon web services SAM节点+;Python lambdas在一起,amazon-web-services,aws-lambda,aws-codebuild,aws-serverless,Amazon Web Services,Aws Lambda,Aws Codebuild,Aws Serverless,是否可以在同一个模板文件中同时运行Node和Python lambda,并通过CodePipeline+CodeBuild进行构建?我经常遇到的错误是: Error: NodejsNpmBuilder:Resolver - Path resolution for runtime: nodejs14.x of binary: npm was not successful . . . [Container] 2021/04/07 01:34:55 Expanding packaged.yaml [C
Error: NodejsNpmBuilder:Resolver - Path resolution for runtime: nodejs14.x of binary: npm was not successful
.
.
.
[Container] 2021/04/07 01:34:55 Expanding packaged.yaml
[Container] 2021/04/07 01:34:55 Skipping invalid file path packaged.yaml
[Container] 2021/04/07 01:34:55 Phase complete: UPLOAD_ARTIFACTS State: FAILED
[Container] 2021/04/07 01:34:55 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found
我的模板文件如下所示:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: > MyProject
Globals:
Function:
Timeout: 3
Runtime: python3.8
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/hello_world/ # python
Events:
HelloWorldApiEvent:
Type: Api
Properties:
Path: /hello
Method: GET
GetPresignedUrl:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/get_presigned_url/
Runtime: nodejs14.x
Handler: index.handler
phases:
install:
commands:
- echo "[Install phase]"
pre_build:
commands:
- pip3 install aws-sam-cli
build:
commands:
- echo "[Build phase]"
- sam build --debug
- sam package --template-file template.yaml --s3-bucket $BUILD_OUTPUT_BUCKET --output-template-file packaged.yaml
post_build:
commands:
- echo "[Post-Build phase]"
- echo "SAM packaging completed on `date`"
artifacts:
type: zip
files:
- packaged.yaml
discard-paths: yes
CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: MyProject
Description: Build project for MyProject
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: public.ecr.aws/bitnami/python:3.8.7-prod
EnvironmentVariables:
-
Name: BUILD_OUTPUT_BUCKET
Value: !Ref BuildArtifactsBucket
我的buildspec.yml文件如下所示:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: > MyProject
Globals:
Function:
Timeout: 3
Runtime: python3.8
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/hello_world/ # python
Events:
HelloWorldApiEvent:
Type: Api
Properties:
Path: /hello
Method: GET
GetPresignedUrl:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/get_presigned_url/
Runtime: nodejs14.x
Handler: index.handler
phases:
install:
commands:
- echo "[Install phase]"
pre_build:
commands:
- pip3 install aws-sam-cli
build:
commands:
- echo "[Build phase]"
- sam build --debug
- sam package --template-file template.yaml --s3-bucket $BUILD_OUTPUT_BUCKET --output-template-file packaged.yaml
post_build:
commands:
- echo "[Post-Build phase]"
- echo "SAM packaging completed on `date`"
artifacts:
type: zip
files:
- packaged.yaml
discard-paths: yes
CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: MyProject
Description: Build project for MyProject
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: public.ecr.aws/bitnami/python:3.8.7-prod
EnvironmentVariables:
-
Name: BUILD_OUTPUT_BUCKET
Value: !Ref BuildArtifactsBucket
My pipeline.yml文件指定使用python映像。My pipeline.yml看起来像这样:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: > MyProject
Globals:
Function:
Timeout: 3
Runtime: python3.8
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/hello_world/ # python
Events:
HelloWorldApiEvent:
Type: Api
Properties:
Path: /hello
Method: GET
GetPresignedUrl:
Type: AWS::Serverless::Function
Properties:
CodeUri: lambdas/get_presigned_url/
Runtime: nodejs14.x
Handler: index.handler
phases:
install:
commands:
- echo "[Install phase]"
pre_build:
commands:
- pip3 install aws-sam-cli
build:
commands:
- echo "[Build phase]"
- sam build --debug
- sam package --template-file template.yaml --s3-bucket $BUILD_OUTPUT_BUCKET --output-template-file packaged.yaml
post_build:
commands:
- echo "[Post-Build phase]"
- echo "SAM packaging completed on `date`"
artifacts:
type: zip
files:
- packaged.yaml
discard-paths: yes
CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Name: MyProject
Description: Build project for MyProject
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: public.ecr.aws/bitnami/python:3.8.7-prod
EnvironmentVariables:
-
Name: BUILD_OUTPUT_BUCKET
Value: !Ref BuildArtifactsBucket
任何帮助都将不胜感激