# AwsCustomResourcePolicy

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

Obtainable from: AwsCustomResourcePolicy.fromSdkCalls, AwsCustomResourcePolicy.fromStatements

- Source: [`custom-resources/lib/aws-custom-resource/aws-custom-resource.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts#L249)

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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 }
    }) })
});
```

Golang:

```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_RESOURCE`: string[] (static) — Use this constant to configure access to any resource.

- `resources`: string[] — resources for auto-generated from SDK calls.

- `statements`: [PolicyStatement](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.PolicyStatement.html)[] — statements for explicit policy.

## Methods

- `fromSdkCalls(options: SdkCallsPolicyOptions): AwsCustomResourcePolicy // chainable` (static) — Generate IAM Policy Statements from the configured SDK calls.

  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**

  - `options` — options for the policy generation.

- `fromStatements(statements: PolicyStatement[]): AwsCustomResourcePolicy // chainable` (static) — Explicit IAM Policy Statements.

  **Parameters**

  - `statements` — the statements to propagate to the SDK calls.
