Skip to content

Commit

Permalink
EREGCSC-2922 Advance CDK deploy to val account (#1564)
Browse files Browse the repository at this point in the history
* Advance CDK deploy to val account

* Fix lambda invoke commands for CDK

-- Previous syntax would fail if FunctionError present in lambda response,
but not if AWS CLI encountered an error trying to invoke.
  • Loading branch information
cgodwin1 authored Feb 20, 2025
1 parent 7c7aa4c commit e010a2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy CDK to DEV
name: Deploy CDK

on:
workflow_dispatch:
Expand All @@ -18,7 +18,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down Expand Up @@ -193,11 +193,10 @@ jobs:
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
run: |
# This unusual bash syntax is necessary because the AWS CLI doesn't return a non-zero exit code when the lambda fails.
# If lambda fails, "FunctionError" will be present in the stdout output. First copy the output to stderr so we can see it,
# then grep for "FunctionError" and fail if it's present (grep returns 0 if it finds the string, then we invert that with '!')
! aws lambda invoke --function-name cms-eregs-${{ matrix.environment }}-migrate /dev/stdout | tee /dev/stderr | grep FunctionError > /dev/null
! aws lambda invoke --function-name cms-eregs-${{ matrix.environment }}-createsu /dev/stdout | tee /dev/stderr | grep FunctionError > /dev/null
aws lambda invoke --function-name cms-eregs-${{ matrix.environment }}-migrate /dev/stdout | tee -a aws.log
aws lambda invoke --function-name cms-eregs-${{ matrix.environment }}-createsu /dev/stdout | tee -a aws.log
# Check for invocation errors
! grep -q FunctionError aws.log
- name: Get API URL
id: get-api-url
Expand All @@ -213,7 +212,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down Expand Up @@ -252,7 +251,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down Expand Up @@ -291,7 +290,7 @@ jobs:
strategy:
max-parallel: 1
matrix:
environment: ["dev"]
environment: ["dev", "val"]
runs-on: ubuntu-22.04
environment:
name: ${{ matrix.environment }}
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/deploy-experimental-cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,11 @@ jobs:
AWS_DEFAULT_REGION: ${{ vars.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
run: |
# This unusual bash syntax is necessary because the AWS CLI doesn't return a non-zero exit code when the lambda fails.
# If lambda fails, "FunctionError" will be present in the stdout output. First copy the output to stderr so we can see it,
# then grep for "FunctionError" and fail if it's present (grep returns 0 if it finds the string, then we invert that with '!')
! aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-createdb /dev/stdout | tee /dev/stderr | grep FunctionError > /dev/null
! aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-migrate /dev/stdout | tee /dev/stderr | grep FunctionError > /dev/null
! aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-createsu /dev/stdout | tee /dev/stderr | grep FunctionError > /dev/null
aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-createdb /dev/stdout | tee -a aws.log
aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-migrate /dev/stdout | tee -a aws.log
aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-createsu /dev/stdout | tee -a aws.log
# Check for invocation errors
! grep -q FunctionError aws.log
- name: Get API URL
id: get-api-url
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/remove-experimental-cdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,17 @@ jobs:
npm install
# Delete the database for this ephemeral environment
# This unusual bash syntax is necessary because the AWS CLI doesn't return a non-zero exit code when the lambda fails.
# If lambda fails, "FunctionError" will be present in the stdout output. First copy the output to stderr so we can see it,
# then grep for "FunctionError" and fail if it's present (grep returns 0 if it finds the string, then we invert that with '!')
echo "Deleting database for PR: ${PR_NUMBER}"
! aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-dropdb /dev/stdout | tee /dev/stderr | grep FunctionError > /dev/null
aws lambda invoke --function-name cms-eregs-eph-$PR_NUMBER-dropdb /dev/stdout | tee -a aws.log
# Check for invocation errors
! grep -q FunctionError aws.log
# Generate the stack names for this PR
TEXT_EXTRACTOR_STACK="cms-eregs-eph-${PR_NUMBER}-text-extractor"
FR_PARSER_STACK="cms-eregs-eph-${PR_NUMBER}-fr-parser"
ECFR_PARSER_STACK="cms-eregs-eph-${PR_NUMBER}-ecfr-parser"
API_STACK="cms-eregs-eph-${PR_NUMBER}-api"
# Destroy fr-parser stack
echo "Destroying PR-specific stack: ${FR_PARSER_STACK}"
cdk destroy "${FR_PARSER_STACK}" \
Expand Down Expand Up @@ -162,4 +160,4 @@ jobs:
--app "npx ts-node bin/zip-lambdas.ts"
echo "Cleanup completed for stack: ${STACK_NAME}"
popd
popd

0 comments on commit e010a2b

Please sign in to comment.