Skip to content

Commit

Permalink
EREGCSC-2856 - Add text extractor CDK stack (#1486)
Browse files Browse the repository at this point in the history
* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk

* Add text extract stack cdk
  • Loading branch information
addis-samtek authored Nov 22, 2024
1 parent 1ce16fa commit 1b736d0
Show file tree
Hide file tree
Showing 6 changed files with 503 additions and 15 deletions.
47 changes: 45 additions & 2 deletions .github/workflows/deploy-experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
npm install
cdk deploy "*redirect-api" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never
--require-approval never
popd
deploy-Maintenance-Api-CDK:
environment:
Expand Down Expand Up @@ -199,8 +199,51 @@ jobs:
npm install
cdk deploy "*maintenance-api" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never
--require-approval never
popd
deploy-Text-extractor-CDK:
environment:
name: "dev"
env:
ENVIRONMENT_NAME: "dev"
runs-on: ubuntu-22.04
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy Text extract via CDK
id: deploy-text-extractor
if: success() && steps.findPr.outputs.number
env:
PR_NUMBER: ${{ steps.findPr.outputs.pr }}
RUN_ID: ${{ github.run_id }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT_NAME }}
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
cdk deploy "*-text-extractor" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never
popd
deploy-text-extractor:
environment:
name: "dev"
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/remove-experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,27 @@ jobs:
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force
echo "Cleanup completed for stack: ${STACK_NAME}"
popd
- name: Destroy PR-Text-extract Stack
env:
PR_NUMBER: ${{ github.event.number }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
ENVIRONMENT_NAME: ${{ env.ENVIRONMENT_NAME }}
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
# Generate the exact stack name for this PR
STACK_NAME="cms-eregs-eph-${PR_NUMBER}-text-extractor"
echo "Destroying PR-specific stack: ${STACK_NAME}"
cdk destroy "${STACK_NAME}" \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--force
echo "Cleanup completed for stack: ${STACK_NAME}"
popd
44 changes: 31 additions & 13 deletions cdk-eregs/bin/cdk-eregs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@ import { IamPermissionsBoundaryAspect } from '../lib/aspects/iam-permissions-bou
import { EphemeralRemovalPolicyAspect } from '../lib/aspects/removal-policy-aspect';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { MaintenanceApiStack } from '../lib/stacks/maintainance-stack';

import { TextExtractorStack } from '../lib/stacks/text-extract-stack';
// import { StackFactory } from '../lib/factories/stack-factory';
// import { getStackConfigs } from '../config/stack-definition';
async function main() {
// Initialize CDK App with synthesizer configuration
// const synthesizerConfigJson = await getParameterValue('/cms/cloud/cdkSynthesizerConfig');
const synthesizerConfigJson = await getParameterValue('/eregulations/cdk_config');
const synthesizerConfig = JSON.parse(synthesizerConfigJson);
const [vpcId, logLevel, httpUser, httpPassword] = await Promise.all([
getParameterValue('/account_vars/vpc/id'),
getParameterValue('/eregulations/text_extractor/log_level'),
getParameterValue('/eregulations/http/user'),
getParameterValue('/eregulations/http/password'),
]);
// Get environment configuration
const env = {
account: process.env.CDK_DEFAULT_ACCOUNT || process.env.AWS_ACCOUNT_ID,
region: process.env.CDK_DEFAULT_REGION || 'us-east-1'
};
const app = new cdk.App({
defaultStackSynthesizer: new cdk.DefaultStackSynthesizer(synthesizerConfig),
});

// Get bundling type from context
const bundlingType = app.node.tryGetContext('bundling');
const environment = app.node.tryGetContext('environment') ||
process.env.DEPLOY_ENV ||
process.env.GITHUB_JOB_ENVIRONMENT ||
Expand Down Expand Up @@ -71,16 +83,8 @@ async function main() {
cdk.Tags.of(app).add(key, value);
});

// // Create and configure stacks
// const stackFactory = new StackFactory(app, stageConfig);
// const stackConfigs = getStackConfigs(environment, stageConfig.isEphemeral());

// const stacks = stackConfigs
// .filter(config => config.enabled)
// .map(config => stackFactory.createStack(config))
// .filter((stack): stack is cdk.Stack => stack !== null);
// Create RedirectApiStack
new RedirectApiStack(app, stageConfig.getResourceName('redirect-api'), {
new RedirectApiStack(app, stageConfig.getResourceName('redirect-api'), {
lambdaConfig: {
runtime: lambda.Runtime.PYTHON_3_12,
memorySize: 1024,
Expand All @@ -90,7 +94,7 @@ async function main() {
loggingLevel: cdk.aws_apigateway.MethodLoggingLevel.INFO,
},
}, stageConfig);
new MaintenanceApiStack(app, stageConfig.getResourceName('maintenance-api'), {
new MaintenanceApiStack(app, stageConfig.getResourceName('maintenance-api'), {
lambdaConfig: {
runtime: lambda.Runtime.PYTHON_3_12,
memorySize: 1024,
Expand All @@ -100,7 +104,21 @@ async function main() {
loggingLevel: cdk.aws_apigateway.MethodLoggingLevel.INFO,
},
}, stageConfig);
// Example deployment in app.ts

new TextExtractorStack(app, stageConfig.getResourceName('text-extractor'), {
env,
lambdaConfig: {
memorySize: 1024,
timeout: 900,
reservedConcurrentExecutions: 10,
},
environmentConfig: {
vpcId,
logLevel,
httpUser,
httpPassword,
}
}, stageConfig);

// Apply aspects
await applyGlobalAspects(app, stageConfig);
Expand Down
44 changes: 44 additions & 0 deletions cdk-eregs/cdk.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,49 @@
]
}
]
},
"vpc-provider:account=910670052382:filter.vpc-id=vpc-0b4ec773c3a0aff85:region=us-east-1:returnAsymmetricSubnets=true": {
"vpcId": "vpc-0b4ec773c3a0aff85",
"vpcCidrBlock": "10.147.73.192/26",
"ownerAccountId": "910670052382",
"availabilityZones": [],
"subnetGroups": [
{
"name": "Public",
"type": "Public",
"subnets": [
{
"subnetId": "subnet-06a498eab225d421f",
"cidr": "10.147.73.192/28",
"availabilityZone": "us-east-1a",
"routeTableId": "rtb-0319ac9f2e2587861"
},
{
"subnetId": "subnet-045ffa689dee9bbaf",
"cidr": "10.147.73.224/28",
"availabilityZone": "us-east-1a",
"routeTableId": "rtb-0f86dd33477a534a3"
},
{
"subnetId": "subnet-086a464d9c0e8ec4a",
"cidr": "10.147.73.240/28",
"availabilityZone": "us-east-1b",
"routeTableId": "rtb-0f86dd33477a534a3"
}
]
},
{
"name": "Private",
"type": "Private",
"subnets": [
{
"subnetId": "subnet-020cc2513ecb5e5e4",
"cidr": "10.147.73.208/28",
"availabilityZone": "us-east-1b",
"routeTableId": "rtb-0a8ad3bde1bfa6ba8"
}
]
}
]
}
}
1 change: 1 addition & 0 deletions cdk-eregs/lib/stacks/redirect-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class RedirectApiStack extends cdk.Stack {
runtime: config.runtime,
handler: config.handler ?? 'redirect_lambda.handler',
code: lambda.Code.fromAsset(config.codePath ?? '../solution/backend/'),

memorySize: config.memorySize,
timeout: cdk.Duration.seconds(config.timeout),
role,
Expand Down
Loading

0 comments on commit 1b736d0

Please sign in to comment.