# IdentityPoolRoleMapping

Map roles to users in the Identity Pool based on claims from the Identity Provider.

- Source: [`aws-cognito-identitypool/lib/identitypool.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-cognito-identitypool/lib/identitypool.ts#L282)
- Type last changed: v2.186.0 · 27 Mar 2025

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_cognito_identitypool as cognito_identitypool } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';

declare const identityPoolProviderUrl: cognito_identitypool.IdentityPoolProviderUrl;
declare const role: iam.Role;
const identityPoolRoleMapping: cognito_identitypool.IdentityPoolRoleMapping = {
  providerUrl: identityPoolProviderUrl,

  // the properties below are optional
  mappingKey: 'mappingKey',
  resolveAmbiguousRoles: false,
  rules: [{
    claim: 'claim',
    claimValue: 'claimValue',
    mappedRole: role,

    // the properties below are optional
    matchType: cognito_identitypool.RoleMappingMatchType.EQUALS,
  }],
  useToken: false,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_cognito_identitypool as cognito_identitypool
from aws_cdk import aws_iam as iam

# identity_pool_provider_url: cognito_identitypool.IdentityPoolProviderUrl
# role: iam.Role

identity_pool_role_mapping = cognito_identitypool.IdentityPoolRoleMapping(
    provider_url=identity_pool_provider_url,

    # the properties below are optional
    mapping_key="mappingKey",
    resolve_ambiguous_roles=False,
    rules=[cognito_identitypool.RoleMappingRule(
        claim="claim",
        claim_value="claimValue",
        mapped_role=role,

        # the properties below are optional
        match_type=cognito_identitypool.RoleMappingMatchType.EQUALS
    )],
    use_token=False
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.cognito.identitypool.*;
import software.amazon.awscdk.services.iam.*;

IdentityPoolProviderUrl identityPoolProviderUrl;
Role role;

IdentityPoolRoleMapping identityPoolRoleMapping = IdentityPoolRoleMapping.builder()
        .providerUrl(identityPoolProviderUrl)

        // the properties below are optional
        .mappingKey("mappingKey")
        .resolveAmbiguousRoles(false)
        .rules(List.of(RoleMappingRule.builder()
                .claim("claim")
                .claimValue("claimValue")
                .mappedRole(role)

                // the properties below are optional
                .matchType(RoleMappingMatchType.EQUALS)
                .build()))
        .useToken(false)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.Cognito.Identitypool;
using Amazon.CDK.AWS.IAM;

IdentityPoolProviderUrl identityPoolProviderUrl;
Role role;

var identityPoolRoleMapping = new IdentityPoolRoleMapping {
    ProviderUrl = identityPoolProviderUrl,

    // the properties below are optional
    MappingKey = "mappingKey",
    ResolveAmbiguousRoles = false,
    Rules = new [] { new RoleMappingRule {
        Claim = "claim",
        ClaimValue = "claimValue",
        MappedRole = role,

        // the properties below are optional
        MatchType = RoleMappingMatchType.EQUALS
    } },
    UseToken = false
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var identityPoolProviderUrl IdentityPoolProviderUrl
var role Role

identityPoolRoleMapping := &IdentityPoolRoleMapping{
	ProviderUrl: identityPoolProviderUrl,

	// the properties below are optional
	MappingKey: jsii.String("mappingKey"),
	ResolveAmbiguousRoles: jsii.Boolean(false),
	Rules: []RoleMappingRule{
		&RoleMappingRule{
			Claim: jsii.String("claim"),
			ClaimValue: jsii.String("claimValue"),
			MappedRole: role,

			// the properties below are optional
			MatchType: awscdk.Aws_cognito_identitypool.RoleMappingMatchType_EQUALS,
		},
	},
	UseToken: jsii.Boolean(false),
}
```

## Properties

- `mappingKey`: string — The key used for the role mapping in the role mapping hash.

  **Default:** The provided providerUrl

  Required if the providerUrl is a token.

- `providerUrl`: [IdentityPoolProviderUrl](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito_identitypool.IdentityPoolProviderUrl.html) (required) — The url of the Provider for which the role is mapped.

- `resolveAmbiguousRoles`: boolean — Allow for role assumption when results of role mapping are ambiguous.

  **Default:** false - Ambiguous role resolutions will lead to requester being denied

- `rules`: [RoleMappingRule](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cognito_identitypool.RoleMappingRule.html)[] — The claim and value that must be matched in order to assume the role.

  **Default:** No role mapping rule

  Required if useToken is false

- `useToken`: boolean = false — If true then mapped roles must be passed through the cognito:roles or cognito:preferred_role claims from Identity Provider.
