Chalice Cloudformation CI/CD pipeline multiple accounts (AWS Organizations)

0

In a Chalice Lambda that is build using AWS Pipelines, how do I (best) configure and deploy different system environment variables for each of our AWS Organizations account (dev vs qa vs prod).

Example: Do I need to run chalice package --stage 3 times and create 3 different artifacts (bit inefficient)?

buildspec.yaml

version: 0.2
phases:
  install:
    runtime-versions:
      python: 3.8
    commands:
      - pip3 install --upgrade pip
      - pip3 install --upgrade awscli
      - aws --version
      - pip3 install chalice
      - pip3 install -r requirements.txt
      - chalice package /tmp/packaged
      - aws cloudformation package --template-file /tmp/packaged/sam.json --s3-bucket ${APP_S3_BUCKET} --output-template-file transformed.yaml
artifacts:
  type: zip
  files:
    - transformed.yaml

config.json:
{
  "version": "2.0",
  "app_name": "budderfly-ke2portal",
  "iam_policy_file": "policy.json",
  "autogen_policy": false,
  "stages": {
    "dev": {
      "api_gateway_stage": "api",
     "IOT_DATA_ENDPOINT": "https://dev-ats.iot.us-west-2.amazonaws.com"
    },
    "qa": {
      "api_gateway_stage": "api",
     "IOT_DATA_ENDPOINT": "https://qa-ats.iot.us-west-2.amazonaws.com"
    },
    "prod": {
      "api_gateway_stage": "api",
      "IOT_DATA_ENDPOINT": "https://prod-ats.iot.us-west-2.amazonaws.com"
    }
  }
}
  • chalice package is creating the final package, so yes you will have to run it 3 times. to create different packages for different environments. You can do that in single build or 3 different builds.

1 Antwort
1
Akzeptierte Antwort

Hello,

To create 3 different artifacts/packages for the respective environments, the chalice package command would have to be run 3 times. This can be done in the same build by adding the various commands and then outputting the artifacts as secondary artifacts. Also, the commands can also be run separately in a pipeline using 3 different build stages. See an example of outputting multiple artifacts here.

AWS
beantwortet vor 2 Jahren
  • Thank you. I now ended up using resource files in Chalice, i.e.:

          - chalice package --merge-template dev.json /tmp/dev
          - chalice package --merge-template qa.json /tmp/qa
          - chalice package --merge-template prod.json /tmp/prod
          - aws cloudformation package --template-file /tmp/dev/sam.json --s3-bucket ${APP_S3_BUCKET} --output-template-file devtransformed.yaml
          - aws cloudformation package --template-file /tmp/qa/sam.json --s3-bucket ${APP_S3_BUCKET} --output-template-file qatransformed.yaml
          - aws cloudformation package --template-file /tmp/prod/sam.json --s3-bucket ${APP_S3_BUCKET} --output-template-file prodtransformed.yaml
    

    with:

    artifacts:
      files:
        - "*.yaml"
      secondary-artifacts:
        devartifacts:
    #      base-directory: $CODEBUILD_SRC_DIR
          files:
            - devtransformed.yaml
        qaartifacts:
    #      base-directory: $CODEBUILD_SRC_DIR
          files:
            - qatransformed.yaml
        prodartifacts:
    #      base-directory: $CODEBUILD_SRC_DIR
          files:
            - prodtransformed.yaml
    

    then update the codecommit pipeline to use those 3 artifacts.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen