Skip to content

Commit

Permalink
chore(cdk-ops): output ARN of load-access-logs
Browse files Browse the repository at this point in the history
- `CdkOpsStack` outputs the ARN of `lambda/load-access-logs`.
  `DataWarehouse` exposes `lambda/load-access-logs`.

issue codemonger-io#30
  • Loading branch information
kikuomax committed Oct 11, 2022
1 parent 8a58bc9 commit 605f682
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 16 additions & 7 deletions cdk-ops/lib/cdk-ops-stack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, StackProps } from 'aws-cdk-lib';
import { CfnOutput, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';

import { AccessLogsETL } from './access-logs-etl';
Expand Down Expand Up @@ -31,22 +31,31 @@ export class CdkOpsStack extends Stack {
const pipeline = new ContentsPipeline(this, 'ContentsPipeline', {
codemongerResources,
});
const dataWarehouse = new DataWarehouse(this, 'DevelopmentDataWarehouse', {
latestBoto3,
libdatawarehouse,
deploymentStage: 'development',
});
const developmentDataWarehouse = new DataWarehouse(
this,
'DevelopmentDataWarehouse',
{
latestBoto3,
libdatawarehouse,
deploymentStage: 'development',
},
);
const developmentContentsAccessLogsETL = new AccessLogsETL(
this,
'DevelopmentContentsAccessLogsETL',
{
accessLogsBucket:
codemongerResources.developmentContentsAccessLogsBucket,
dataWarehouse,
dataWarehouse: developmentDataWarehouse,
latestBoto3,
libdatawarehouse,
deploymentStage: 'development',
},
);
// Outputs
new CfnOutput(this, 'PopulateDevelopmentDwDatabaseLambdaArn', {
description: 'ARN of the Lambda function that populates the data warehouse database and tables (development)',
value: developmentDataWarehouse.populateDwDatabaseLambda.functionArn,
});
}
}
8 changes: 5 additions & 3 deletions cdk-ops/lib/data-warehouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class DataWarehouse extends Construct {
readonly workgroupName: string;
/** Redshift Serverless workgroup. */
readonly workgroup: redshift.CfnWorkgroup;
/** Lambda function to populate the database and tables. */
readonly populateDwDatabaseLambda: lambda.IFunction;
/** Step Functions to run VACUUM over tables. */
readonly vacuumWorkflow: sfn.IStateMachine;

Expand Down Expand Up @@ -140,7 +142,7 @@ export class DataWarehouse extends Construct {
this.workgroup.addDependsOn(dwNamespace);

// Lambda function that populates the database and tables.
const populateDwDatabaseLambda = new PythonFunction(
this.populateDwDatabaseLambda = new PythonFunction(
this,
'PopulateDwDatabaseLambda',
{
Expand Down Expand Up @@ -169,9 +171,9 @@ export class DataWarehouse extends Construct {
);
// Redshift Data API uses the execution role of the Lambda function to
// retrieve the secret.
this.adminSecret.grantRead(populateDwDatabaseLambda);
this.adminSecret.grantRead(this.populateDwDatabaseLambda);
// TODO: too permissive?
populateDwDatabaseLambda.role?.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonRedshiftDataFullAccess'));
this.populateDwDatabaseLambda.role?.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonRedshiftDataFullAccess'));

// Step Functions that perform VACUUM over tables.
// - Lambda function that runs VACUUM over a given table
Expand Down

0 comments on commit 605f682

Please sign in to comment.