From 41d57cda68cebff4001687b6700f827e9584859b Mon Sep 17 00:00:00 2001 From: Laren-AWS Date: Fri, 26 Apr 2024 11:32:57 -0700 Subject: [PATCH] Testing CDK refactor. --- .../cdk/lib/pools-and-triggers-stack-for-go.ts | 13 +++++++------ .../user_pools_and_lambda_triggers/cdk/bin/cdk.ts | 8 -------- ...triggers-stack.ts => pools-and-triggers-base.ts} | 6 +++--- 3 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 workflows/user_pools_and_lambda_triggers/cdk/bin/cdk.ts rename workflows/user_pools_and_lambda_triggers/cdk/lib/{pools-and-triggers-stack.ts => pools-and-triggers-base.ts} (93%) diff --git a/gov2/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack-for-go.ts b/gov2/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack-for-go.ts index dab2d3a0ef0..17e0013e1c6 100644 --- a/gov2/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack-for-go.ts +++ b/gov2/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack-for-go.ts @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { PoolsAndTriggersStack } from '../../../../../workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack'; +import { PoolsAndTriggersBase } from '../../../../../workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-base'; import * as cdk from 'aws-cdk-lib'; import {CfnOutput} from 'aws-cdk-lib'; import {Construct} from 'constructs'; @@ -13,16 +13,16 @@ export class PoolsAndTriggersStackForGo extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); - const baseStack = new PoolsAndTriggersStack(this, "PoolsAndTriggersStack"); + const baseConstruct = new PoolsAndTriggersBase(this, "PoolsAndTriggersBase"); const cognitoPrincipal = new iam.ServicePrincipal("cognito-idp.amazonaws.com"); const autoConfirmFunction = this.createFunction('autoConfirmHandler', '../handlers/auto_confirm', - baseStack.tableName, baseStack.lambdaRole, cognitoPrincipal); + baseConstruct.tableName, baseConstruct.lambdaRole, cognitoPrincipal); const migrateUserFunction = this.createFunction('migrateUserHandler', '../handlers/migrate_user', - baseStack.tableName, baseStack.lambdaRole, cognitoPrincipal); + baseConstruct.tableName, baseConstruct.lambdaRole, cognitoPrincipal); const activityLogFunction = this.createFunction('activityLogHandler', '../handlers/activity_log', - baseStack.tableName, baseStack.lambdaRole, cognitoPrincipal); + baseConstruct.tableName, baseConstruct.lambdaRole, cognitoPrincipal); new CfnOutput(this, "AutoConfirmFunction", {value: autoConfirmFunction.functionName}) new CfnOutput(this, "AutoConfirmFunctionArn", {value: autoConfirmFunction.functionArn}) @@ -30,7 +30,7 @@ export class PoolsAndTriggersStackForGo extends cdk.Stack { new CfnOutput(this, "MigrateUserFunctionArn", {value: migrateUserFunction.functionArn}) new CfnOutput(this, "ActivityLogFunction", {value: activityLogFunction.functionName}) new CfnOutput(this, "ActivityLogFunctionArn", {value: activityLogFunction.functionArn}) - baseStack.outputs(this) + baseConstruct.outputs(this) } createFunction(name: string, path: string, tableName: string, lambdaRole: iam.IRole, principal: iam.IGrantable) { @@ -40,6 +40,7 @@ export class PoolsAndTriggersStackForGo extends cdk.Stack { "TABLE_NAME": tableName }, role: lambdaRole, + moduleDir: '..', }); fn.grantInvoke(principal) return fn diff --git a/workflows/user_pools_and_lambda_triggers/cdk/bin/cdk.ts b/workflows/user_pools_and_lambda_triggers/cdk/bin/cdk.ts deleted file mode 100644 index dbdd034615b..00000000000 --- a/workflows/user_pools_and_lambda_triggers/cdk/bin/cdk.ts +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env node -import 'source-map-support/register'; -import * as cdk from 'aws-cdk-lib'; -import { PoolsAndTriggersStack } from '../lib/pools-and-triggers-stack'; - -const app = new cdk.App(); -new PoolsAndTriggersStack(app, 'PoolsAndTriggersStack', { -}); \ No newline at end of file diff --git a/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack.ts b/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-base.ts similarity index 93% rename from workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack.ts rename to workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-base.ts index 18c0ef59072..a8e9950dd4c 100644 --- a/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-stack.ts +++ b/workflows/user_pools_and_lambda_triggers/cdk/lib/pools-and-triggers-base.ts @@ -5,15 +5,15 @@ import * as dynamo from 'aws-cdk-lib/aws-dynamodb'; import * as cognito from 'aws-cdk-lib/aws-cognito'; import * as iam from 'aws-cdk-lib/aws-iam'; -export class PoolsAndTriggersStack extends cdk.Stack { +export class PoolsAndTriggersBase extends Construct { readonly tableName: string; readonly userPoolId: string; readonly userPoolArn: string; readonly userPoolClientId: string; readonly lambdaRole: iam.Role; - constructor(scope: Construct, id: string, props?: cdk.StackProps) { - super(scope, id, props); + constructor(scope: Construct, id: string) { + super(scope, id); this.tableName = "doc-example-custom-users" const table = new dynamo.Table(this, "doc-example-custom-users", {