How to deploy and start a new version of AWS Mainframe Modernization application from CI/CD pipeline?

4 minutos de lectura
Nivel de contenido: Avanzado
2

This article explains how to develop AWS Step Functions to automate the Deployment and Start of new version of AWS Mainframe Modernization application. The Step Functions can be triggered from the CI/CD pipeline after the build and test phase.

Introduction

Continuous integration (CI) is a software development practice where members of a team use a version control system and frequently integrate their work to the same location, such as a main branch. Each change is built and verified to detect integration errors as quickly as possible. Continuous delivery (CD) is a software development methodology where the release process is automated. Every software change is automatically built, tested, and deployed to production. Before the final push to production, a person, an automated test, or a business rule decides when the final push should occur. Continuous integration is focused on automatically building and testing code, as compared to continuous delivery, which automates the entire software release process up to production.

CI/CD Pipeline is a continuous delivery service that automates the building, testing, and deployment of your software into production. This article specifically focus on how to implement the deploy phase of a CI/CD pipeline for AWS Mainframe Modernization service using AWS Step Functions; the build, test and approval phase can be implemented following standard methodologies.

CI/CD Phases

A simplified version of the CI/CD pipeline phases.


AWS Step Functions to deploy and start application:

An AWS Step Functions workflow similar to below can be used to deploy a new version of the AWS Mainframe Modernization application and start it. The artifacts to be deployed are generated during the build phase of the CI/CD pipeline (not covered here) and stored in S3 bucket. The application definition within the Step Functions points to the location on S3 bucket which contains the artifacts to be deployed.

AWS Step Functions

AWS Step Functions Code:

Below is the sample yaml code snippet for the AWS Step Functions above. Replace or parameterize the placeholders such as m2-example-app, Content, etc. as appropriate.

Comment: StepFunction to Deploy AWS Mainframe Modernization Application
StartAt: ListApplications
States:
  ListApplications:
    Next: GetApplicationVersion
    Parameters:
      Names:
        - m2-example-app
    Resource: arn:aws:states:::aws-sdk:m2:listApplications
    Type: Task
  GetApplicationVersion:
    Next: UpdateApplication
    Parameters:
      ApplicationId.$: $.Applications[0].ApplicationId
    Resource: arn:aws:states:::aws-sdk:m2:getApplication
    Type: Task
  UpdateApplication:
    Next: Wait for Update to Complete
    Parameters:
      ApplicationId.$: $.ApplicationId
      CurrentApplicationVersion.$: $.LatestVersion.ApplicationVersion
      Definition:
        Content: |
          {
           "template-version": "2.0",
           "source-locations": [
              {
                  "source-id": "s3-source",
                  "source-type": "s3",
                  "properties": {
                      "s3-bucket": "DOC-EXAMPLE-BUCKET",
                      "s3-key-prefix": "v2"
                  }
              }
            ],
            "definition" : {
              "listeners": [
                {
                  "port": 7000,
                  "type": "http"
                }
              ],
              "ba-application": {
                "app-location": "${s3-source}/artifacts/"
              },
              "blusam": {
                "db": {
                  "secret-manager-arn": "arn:aws:secretsmanager:us-east-1:111122223333:secret:M2DbSecret-heOS8jwYYeO9-F9DYYQ"
                },
                "redis": {
                  "hostname": "example.0001.use1.cache.amazonaws.com",
                  "port": 6379,
                  "useSsl": false
                }
              }
            }
          }
    Resource: arn:aws:states:::aws-sdk:m2:updateApplication
    ResultPath: $.ApplicationVersion
    Type: Task
  Wait for Update to Complete:
    Next: Is Application Running?
    Seconds: 10
    Type: Wait
  Is Application Running?:
    Choices:
      - Comment: Application is already Stopped
        Next: GetApplicationCurrentStatus
        StringEquals: Stopped
        Variable: $.Status
    Default: StopApplication
    Type: Choice
  StopApplication:
    Next: Wait for Application to Stop
    Parameters:
      ApplicationId.$: $.ApplicationId
    Resource: arn:aws:states:::aws-sdk:m2:stopApplication
    ResultPath: $.ApplicationVersion.ApplicationVersion
    Type: Task
  Wait for Application to Stop:
    Next: GetApplicationStopStatus
    Seconds: 10
    Type: Wait
  Application Stopped?:
    Choices:
      - Next: CreateDeployment
        StringEquals: Stopped
        Variable: $.Status
    Default: Wait for Application to Stop
    Type: Choice
  Choice:
    Choices:
      - Next: StartApplication
        StringEquals: Succeeded
        Variable: $.Status
    Default: Wait for Deployment to Complete
    Type: Choice
  GetApplicationStopStatus:
    Next: Application Stopped?
    Parameters:
      ApplicationId.$: $.ApplicationId
    Resource: arn:aws:states:::aws-sdk:m2:getApplication
    Type: Task
  GetApplicationCurrentStatus:
    Next: CreateDeployment
    Parameters:
      ApplicationId.$: $.ApplicationId
    Resource: arn:aws:states:::aws-sdk:m2:getApplication
    Type: Task
  CreateDeployment:
    Next: GetDeployment Status
    Parameters:
      ApplicationId.$: $.ApplicationId
      ApplicationVersion.$: $.LatestVersion.ApplicationVersion
      EnvironmentId.$: $.EnvironmentId
    Resource: arn:aws:states:::aws-sdk:m2:createDeployment
    ResultPath: $.DeploymentId
    Type: Task
  GetDeployment Status:
    Next: Wait for Deployment to Complete
    Parameters:
      ApplicationId.$: $.ApplicationId
      DeploymentId.$: $.DeploymentId.DeploymentId
    Resource: arn:aws:states:::aws-sdk:m2:getDeployment
    Type: Task
  Wait for Deployment to Complete:
    Next: Recheck GetDeployment Status
    Seconds: 20
    Type: Wait
  Recheck GetDeployment Status:
    Next: Choice
    Parameters:
      ApplicationId.$: $.ApplicationId
      DeploymentId.$: $.DeploymentId
    Resource: arn:aws:states:::aws-sdk:m2:getDeployment
    Type: Task
  StartApplication:
    End: true
    Parameters:
      ApplicationId.$: $.ApplicationId
    Resource: arn:aws:states:::aws-sdk:m2:startApplication
    Type: Task

A complete CI/CD pipeline, starting from code check-in, build, test, approval to deployment is demonstrated in the workshop - AWS Mainframe Modernization: Build well-architected mainframe applications on the AWS Cloud


References

[1] AWS Mainframe Modernization documentation

[2] AWS CodePipeline

[3] AWS Mainframe Modernization CI/CD Tutorial