使用 "Error parsing parameter '--zip-file......' " 的 AWS Lambda 函数的 Bitbucket NodeJS 回购管道失败

Failed Bitbucket NodeJS repo Pipeline with AWS Lambda function with "Error parsing parameter '--zip-file......' "

我们的团队在尝试设置用于更新 AWS Lambda 函数的管道时遇到问题。

触发部署后,它会失败并出现以下错误:

Status: Downloaded newer image for bitbucketpipelines/aws-lambda-deploy:0.2.3
INFO: Updating Lambda function.
aws lambda update-function-code --function-name apikey-token-authorizer2 --publish --zip-file fileb://apiGatewayAuthorizer.zip
Error parsing parameter '--zip-file': Unable to load paramfile fileb://apiGatewayAuthorizer.zip: [Errno 2] No such file or directory: 'apiGatewayAuthorizer.zip'
*Failed to update Lambda function code.

看起来脚本找不到工件,但我们不知道为什么。

这里是 bitbucket-pipelines.yml 文件内容:

    image: node:16
# Workflow Configuration
pipelines:
default:
 - parallel:
 - step:
name: Build and Test
caches:
 - node
script:
 - echo Installing source YARN dependencies.
 - yarn install

branches:
testing:
 - parallel:
 - step:
name: Build 
script:
 - apt update && apt install zip
# Exclude files to be ignored
 - echo Zipping package.
 - zip -r apiGatewayAuthorizer.zip . -x *.git* bitbucket-pipelines.yml

artifacts:
 - apiGatewayAuthorizer.zip
- step:
name: Deploy to testing - Update Lambda code
deployment: Test
trigger: manual
script:
 - pipe: atlassian/aws-lambda-deploy:0.2.3
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
FUNCTION_NAME: $LAMBDA_FUNCTION_NAME
COMMAND: 'update'
ZIP_FILE: 'apiGatewayAuthorizer.zip'

有谁知道我在这里错过了什么?

感谢 Atlassian 的 Marc C.,这是解决方案。

Based on your YAML configuration, I can see that you're using Parallel steps.

According to the documentation:

Parallel steps can only use artifacts produced by previous steps, not by steps in the same parallel set.

因此,这就是为什么在“构建”步骤中没有生成工件的原因 因为这 2 个步骤在平行集中。

为此,您只需删除并行配置并使用 multi-steps 代替。这样,第一步可以生成 工件并将其传递到第二步。希望它有帮助,让我 知道怎么回事了。

此致,马克 C

所以我们已经尝试了解决方案并且它奏效了!。 这是新管道:

    pipelines:
  branches:
    testing:
        - step:
            name: Build and Test
            caches:
              - node
            script:
              - echo Installing source YARN dependencies.
              - yarn install
              - apt update && apt install zip
              # Exclude files to be ignored
              - echo Zipping package.
              - zip -r my-deploy.zip . -x *.git* bitbucket-pipelines.yml
            artifacts:
              - my-deploy.zip
        - step:
            name: Deploy to testing - Update Lambda code
            deployment: Test
            trigger: manual
            script:
              - pipe: atlassian/aws-lambda-deploy:0.2.3
                variables:
                  AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                  AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                  AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
                  FUNCTION_NAME: $LAMBDA_FUNCTION_NAME
                  COMMAND: 'update'
                  ZIP_FILE: 'my-deploy.zip'