首页 > 解决方案 > 如何通过 cloudformation 更新我现有的 lambda(不是由 cloudformation 创建的)。通过 cloudformation 建立管道

问题描述

我正在通过创建变更集并执行变更集来设置使用云形成堆栈的管道。但是第一次这会创建另一个 lambda,并且没有办法更新或部署现有创建的 lambda。

构建规范.yml

version: 0.1
phases:
  install:
    commands:
      - echo "nothing to do in install phase"
  pre_build:
    commands:
      - mvn clean install
  build:
    commands:
      - aws cloudformation package --template-file samTemplate.yaml --s3-bucket saurabh-lambda-pipeline --output-template-file outputSamTemplate.yaml
artifacts:
  type: zip
  files:
    - samTemplate.yaml
    - outputSamTemplate.yaml

samTemplate.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: CD Lambda
Resources:
  testLambda:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: testLambda
      Handler: com.test.handler.calculator::handleRequest
      Runtime: java8
      CodeUri: target/emi-calculator.jar
      AutoPublishAlias: prod
      Description: 'Lambda function for CD'
      MemorySize: 128
      Timeout: 30
      Events:
        getAZsAPI:
          Type: Api
          Properties:
            Path: /calculator
            Method: post
      Environment:
        Variables:
          calculatorType: 30

标签: amazon-web-servicesamazon-cloudformationpipeline

解决方案


您可以将现有资源添加到现有的云形成堆栈。AWS 控制台 > Cloudformation > 打开您的堆栈 > 操作 > 导入现有资源。 https://aws.amazon.com/de/blogs/aws/new-import-existing-resources-into-a-cloudformation-stack/ 然后将您的本地 cloudformation 模板与 CloudFormation 中的模板进行比较。


推荐阅读