Created
June 9, 2021 03:54
-
-
Save neilkuan/d1f0b665a0c8b00e6fd7f5db82f847af to your computer and use it in GitHub Desktop.
cdk-v2-example-sts-role.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { App, CfnParameter, Stack, StackProps } from 'aws-cdk-lib'; | |
import * as iam from 'aws-cdk-lib/aws-iam'; | |
import { Construct } from 'constructs'; | |
export class MyStack extends Stack { | |
constructor(scope: Construct, id: string, props: StackProps = {}) { | |
super(scope, id, props); | |
const accountPrincipal = new CfnParameter(this, 'accountid', { | |
default: '', | |
description: 'trainerAccountId', | |
}); | |
const masterRole = new iam.Role(this, 'masters-role', { | |
assumedBy: new iam.AccountPrincipal(accountPrincipal.valueAsString), | |
roleName: 'TrainerSTSRole', | |
}); | |
masterRole.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('ReadOnlyAccess')); | |
} | |
} | |
// for development, use account/region from cdk cli | |
const devEnv = { | |
account: process.env.CDK_DEFAULT_ACCOUNT, | |
region: process.env.CDK_DEFAULT_REGION, | |
}; | |
const app = new App(); | |
new MyStack(app, 'my-stack-dev', { env: devEnv }); | |
// new MyStack(app, 'my-stack-prod', { env: prodEnv }); | |
app.synth(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment