Skip to content
v2.278.0

CustomizeRolesOptions Struct ​

Options for customizing IAM role creation.

Example ​

ts
declare const app: App;
const stack = new Stack(app, 'MyStack');
iam.Role.customizeRoles(this, {
  usePrecreatedRoles: {
    'MyStack/MyLambda/ServiceRole': 'my-role-name',
  }
});
python
# app: App

stack = Stack(app, "MyStack")
iam.Role.customize_roles(self,
    use_precreated_roles={
        "MyStack/MyLambda/ServiceRole": "my-role-name"
    }
)
java
App app;

Stack stack = new Stack(app, "MyStack");
Role.customizeRoles(this, CustomizeRolesOptions.builder()
        .usePrecreatedRoles(Map.of(
                "MyStack/MyLambda/ServiceRole", "my-role-name"))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
App app;

var stack = new Stack(app, "MyStack");
Role.CustomizeRoles(this, new CustomizeRolesOptions {
    UsePrecreatedRoles = new Dictionary<string, string> {
        { "MyStack/MyLambda/ServiceRole", "my-role-name" }
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var app App

stack := awscdk.Newstack(app, jsii.String("MyStack"))
iam.Role_CustomizeRoles(this, &CustomizeRolesOptions{
	UsePrecreatedRoles: map[string]*string{
		"MyStack/MyLambda/ServiceRole": jsii.String("my-role-name"),
	},
})

Properties ​

preventSynthesisoptionalbooleanprevent_synthesisoptionalboolpreventSynthesisoptionalBooleanPreventSynthesisoptionalboolPreventSynthesisoptional*bool = true #
Whether or not to synthesize the resource into the CFN template.

Set this to false if you still want to create the resources and you also want to create the policy report.

usePrecreatedRolesoptional{ [key: string]: string }use_precreated_rolesoptionaltyping.Mapping[str, str]usePrecreatedRolesoptionalMap<String, String>UsePrecreatedRolesoptionalIDictionary<string, string>UsePrecreatedRolesoptional*map[string]*string #
A list of precreated IAM roles to substitute for roles that CDK is creating.

Default: there are no precreated roles. Synthesis will fail if preventSynthesis=true

The constructPath can be either a relative or absolute path from the scope that customizeRoles is used on to the role being created.

example
ts
declare const app: App;

const stack = new Stack(app, 'MyStack');
new iam.Role(stack, 'MyRole', {
 assumedBy: new iam.AccountPrincipal('111111111111'),
});

iam.Role.customizeRoles(stack, {
  usePrecreatedRoles: {
    // absolute path
    'MyStack/MyRole': 'my-precreated-role-name',
    // or relative path from `stack`
    'MyRole': 'my-precreated-role',
  },
});