-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (20 loc) · 799 Bytes
/
app.js
File metadata and controls
26 lines (20 loc) · 799 Bytes
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
const cdk = require('aws-cdk-lib/core');
const iam = require('aws-cdk-lib/aws-iam');
const stackPrefix = process.env.STACK_NAME_PREFIX;
if (!stackPrefix) {
throw new Error('the STACK_NAME_PREFIX environment variable is required');
}
class ImportExistingResourcesStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const retain = process.env.REMOVAL_POLICY === 'retain';
const role = new iam.Role(this, 'MyRole', {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
roleName: `${stackPrefix}-import-role`,
});
role.applyRemovalPolicy(retain ? cdk.RemovalPolicy.RETAIN : cdk.RemovalPolicy.DESTROY);
}
}
const app = new cdk.App();
new ImportExistingResourcesStack(app, `${stackPrefix}-import-existing`);
app.synth();