Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EREGCSC-2856 - Add text extractor CDK stack #1486

Merged
merged 10 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 --tags lambda-type=zip
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 --tags lambda-type=zip
popd
deploy-Text-extract-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-extract
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 --tags lambda-type=docker
popd
deploy-text-extractor:
environment:
name: "dev"
Expand Down
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'), {
const redirectStack = 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'), {
const maintenanceStack = 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

const textExtractorStack = 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
Loading