-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcdk.js
More file actions
49 lines (42 loc) · 1.57 KB
/
cdk.js
File metadata and controls
49 lines (42 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {App, aws_dsql, Stack, Duration} from 'aws-cdk-lib';
import {Code, Function, Runtime} from 'aws-cdk-lib/aws-lambda';
import {Effect, PolicyStatement} from "aws-cdk-lib/aws-iam";
const app = new App();
const region = process.env.CLUSTER_REGION || 'us-east-1';
class DsqlLambdaStack extends Stack {
constructor(scope, id, props) {
super(scope, id, props);
const dsqlCluster = new aws_dsql.CfnCluster(this, 'DsqlCluster', {
deletionProtectionEnabled: false,
tags: [{
key: 'Name', value: 'Lambda single region cluster',
}, {
key: 'Repo', value: 'aws-samples/aurora-dsql-samples',
}],
});
// Define the Lambda function
const dsqlFunction = new Function(this, 'DsqlLambdaSample', {
functionName: 'DsqlLambdaSample',
runtime: Runtime.NODEJS_22_X,
handler: 'lambda.handler',
code: Code.fromAsset('sample'),
timeout: Duration.seconds(30),
memorySize: 256,
environment: {
CLUSTER_ENDPOINT: `${dsqlCluster.attrIdentifier}.dsql.${region}.on.aws`,
CLUSTER_REGION: region
}
});
// Add DSQL permissions to the Lambda function
dsqlFunction.addToRolePolicy(new PolicyStatement({
effect: Effect.ALLOW,
actions: ['dsql:DbConnectAdmin', 'dsql:DbConnect'],
resources: [dsqlCluster.attrResourceArn]
}));
}
}
new DsqlLambdaStack(app, "DsqlSample", {
env: {
region: region
}
})