Skip to content
v2.278.0

AwsCustomResourcePolicy Class ​

The IAM Policy that will be applied to the different calls.

Example ​

ts
const crossAccountRoleArn = 'arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName'; // arn of role deployed in separate account

const callRegion = 'us-west-1'; // sdk call to be made in specified region (optional)

new cr.AwsCustomResource(this, 'CrossAccount', {
  onCreate: {
    assumedRoleArn: crossAccountRoleArn,
    region: callRegion, // optional
    service: 'sts',
    action: 'GetCallerIdentity',
    physicalResourceId: cr.PhysicalResourceId.of('id'),
  },
  policy: cr.AwsCustomResourcePolicy.fromStatements([iam.PolicyStatement.fromJson({
    Effect: "Allow",
    Action: "sts:AssumeRole",
    Resource: crossAccountRoleArn,
  })]),
});
python
cross_account_role_arn = "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName" # arn of role deployed in separate account

call_region = "us-west-1" # sdk call to be made in specified region (optional)

cr.AwsCustomResource(self, "CrossAccount",
    on_create=cr.AwsSdkCall(
        assumed_role_arn=cross_account_role_arn,
        region=call_region,  # optional
        service="sts",
        action="GetCallerIdentity",
        physical_resource_id=cr.PhysicalResourceId.of("id")
    ),
    policy=cr.AwsCustomResourcePolicy.from_statements([iam.PolicyStatement.from_json({
        "Effect": "Allow",
        "Action": "sts:AssumeRole",
        "Resource": cross_account_role_arn
    })])
)
java
String crossAccountRoleArn = "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName"; // arn of role deployed in separate account

String callRegion = "us-west-1"; // sdk call to be made in specified region (optional)

 // sdk call to be made in specified region (optional)
AwsCustomResource.Builder.create(this, "CrossAccount")
        .onCreate(AwsSdkCall.builder()
                .assumedRoleArn(crossAccountRoleArn)
                .region(callRegion) // optional
                .service("sts")
                .action("GetCallerIdentity")
                .physicalResourceId(PhysicalResourceId.of("id"))
                .build())
        .policy(AwsCustomResourcePolicy.fromStatements(List.of(PolicyStatement.fromJson(Map.of(
                "Effect", "Allow",
                "Action", "sts:AssumeRole",
                "Resource", crossAccountRoleArn)))))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var crossAccountRoleArn = "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName"; // arn of role deployed in separate account

var callRegion = "us-west-1"; // sdk call to be made in specified region (optional)

 // sdk call to be made in specified region (optional)
new AwsCustomResource(this, "CrossAccount", new AwsCustomResourceProps {
    OnCreate = new AwsSdkCall {
        AssumedRoleArn = crossAccountRoleArn,
        Region = callRegion,  // optional
        Service = "sts",
        Action = "GetCallerIdentity",
        PhysicalResourceId = PhysicalResourceId.Of("id")
    },
    Policy = AwsCustomResourcePolicy.FromStatements(new [] { PolicyStatement.FromJson(new Dictionary<string, string> {
        { "Effect", "Allow" },
        { "Action", "sts:AssumeRole" },
        { "Resource", crossAccountRoleArn }
    }) })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
crossAccountRoleArn := "arn:aws:iam::OTHERACCOUNT:role/CrossAccountRoleName" // arn of role deployed in separate account

callRegion := "us-west-1" // sdk call to be made in specified region (optional)

 // sdk call to be made in specified region (optional)
cr.NewAwsCustomResource(this, jsii.String("CrossAccount"), &AwsCustomResourceProps{
	OnCreate: &AwsSdkCall{
		AssumedRoleArn: crossAccountRoleArn,
		Region: callRegion,
		 // optional
		Service: jsii.String("sts"),
		Action: jsii.String("GetCallerIdentity"),
		PhysicalResourceId: cr.PhysicalResourceId_Of(jsii.String("id")),
	},
	Policy: cr.AwsCustomResourcePolicy_FromStatements([]PolicyStatement{
		iam.PolicyStatement_FromJson(map[string]*string{
			"Effect": jsii.String("Allow"),
			"Action": jsii.String("sts:AssumeRole"),
			"Resource": crossAccountRoleArn,
		}),
	}),
})

Properties ​

ANY_RESOURCEstring[]ANY_RESOURCEtyping.List[str]ANY_RESOURCEList<String>ANY_RESOURCEstring[]ANY_RESOURCE*[]*string static #
Use this constant to configure access to any resource.
resourcesmay be undefinedstring[]resourcesmay be undefinedtyping.List[str]resourcesmay be undefinedList<String>Resourcesmay be undefinedstring[]Resourcesmay be undefined*[]*string #
resources for auto-generated from SDK calls.
statementsPolicyStatement[]statementstyping.List[PolicyStatement]statementsList<PolicyStatement>StatementsPolicyStatement[]Statements*[]PolicyStatement #
statements for explicit policy.

Methods ​

fromSdkCalls(options: SdkCallsPolicyOptions): AwsCustomResourcePolicy // chainable@staticmethod def from_sdk_calls(options: SdkCallsPolicyOptions) -> AwsCustomResourcePolicypublic static AwsCustomResourcePolicy fromSdkCalls(SdkCallsPolicyOptions options)public static AwsCustomResourcePolicy FromSdkCalls(SdkCallsPolicyOptions options)func FromSdkCalls(Options SdkCallsPolicyOptions) AwsCustomResourcePolicy static #
Generate IAM Policy Statements from the configured SDK calls.
notes · 1 parameter

Each SDK call with be translated to an IAM Policy Statement in the form of: call.service:call.action (e.g s3:PutObject).

This policy generator assumes the IAM policy name has the same name as the API call. This is true in 99% of cases, but there are exceptions (for example, S3's PutBucketLifecycleConfiguration requires s3:PutLifecycleConfiguration permissions, Lambda's Invoke requires lambda:InvokeFunction permissions). Use fromStatements if you want to do a call that requires different IAM action names.

Parameters

  • optionsoptionsoptionsoptionsOptions — options for the policy generation.
fromStatements(statements: PolicyStatement[]): AwsCustomResourcePolicy // chainable@staticmethod def from_statements(statements: typing.List[PolicyStatement]) -> AwsCustomResourcePolicypublic static AwsCustomResourcePolicy fromStatements(List<PolicyStatement> statements)public static AwsCustomResourcePolicy FromStatements(PolicyStatement[] statements)func FromStatements(Statements *[]PolicyStatement) AwsCustomResourcePolicy static #
Explicit IAM Policy Statements.
1 parameter

Parameters

  • statementsstatementsstatementsstatementsStatements — the statements to propagate to the SDK calls.