即使在成功执行 CodeBuild 管道后,Lambda 函数也不会更新

Lambda function is not updated even after successful execution of CodeBuild Pipeline

最近在 AWS 上设置了一个基本的 CodePipeline(遵循本指南:https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html),当 CodeCommit 存储库上有新提交时触发。

但是即使在管道成功执行后,lambda 函数也没有更新。

我的buildspec.yml:

version: 0.2
phases:
  install:
    runtime-versions:
        nodejs: 12
  build:
    commands:
      - npm install
      - export BUCKET=xx-test
      - aws cloudformation package --template-file template.yaml --s3-bucket $BUCKET --output-template-file outputtemplate.yml
artifacts:
  type: zip
  files:
    - template.yml
    - outputtemplate.yml

我的template.yaml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  helloWorld
  API Gateway connectivity helloWorld
  
Globals:
  Function:
    Timeout: 3

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: ./
      Handler: app.lambdaHandler
      Runtime: nodejs12.x
      Events:
        HelloWorld:
          Type: Api
          Properties:
            Path: /hello
            Method: get

是否需要进行任何额外配置?

从您发布的内容来看,您的最后一个操作似乎是 CHANGE_SET_REPLACE?如果是这样,这就可以解释为什么您的 lambda 函数没有更新。也就是说,这只会创建一个变更集,但不会不执行它。换句话说,它不适用它。

您需要在 CHANGE_SET_REPLACE 操作后添加新操作,称为 CHANGE_SET_EXECUTE。此操作将采用 CHANGE_SET_REPLACE 创建的更改,并将其实际应用到您的堆栈。

您提供的教程 Complete the deployment stage 中描述了如何添加此类操作:

Change sets let you preview the changes that are made before making them, and add approval stages. Add a second action that executes the change set to complete the deployment.