# IamResource

A class used to generate resource arns for AppSync.

Obtainable from: IamResource.all, IamResource.custom, IamResource.ofType
Used as argument in: [IGraphqlApi.grant](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.IGraphqlApi.html#grant)

- Source: [`aws-appsync/lib/graphqlapi-base.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-appsync/lib/graphqlapi-base.ts#L70)
- Type last changed: v2.131.0 · 1 Mar 2024

## Example

TypeScript:

```ts
const role = new iam.Role(this, 'Role', {
  assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
});
declare const api: appsync.IGraphqlApi;

api.grant(role, appsync.IamResource.custom('types/Mutation/fields/updateExample'), 'appsync:GraphQL');
```

Python:

```python
# api: appsync.IGraphqlApi
role = iam.Role(self, "Role",
    assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
)

api.grant(role, appsync.IamResource.custom("types/Mutation/fields/updateExample"), "appsync:GraphQL")
```

Java:

```java
IGraphqlApi api;
Role role = Role.Builder.create(this, "Role")
        .assumedBy(new ServicePrincipal("lambda.amazonaws.com"))
        .build();

api.grant(role, IamResource.custom("types/Mutation/fields/updateExample"), "appsync:GraphQL");
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
IGraphqlApi api;
var role = new Role(this, "Role", new RoleProps {
    AssumedBy = new ServicePrincipal("lambda.amazonaws.com")
});

api.Grant(role, IamResource.Custom("types/Mutation/fields/updateExample"), "appsync:GraphQL");
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var api IGraphqlApi
role := iam.NewRole(this, jsii.String("Role"), &RoleProps{
	AssumedBy: iam.NewServicePrincipal(jsii.String("lambda.amazonaws.com")),
})

api.Grant(role, appsync.IamResource_Custom(jsii.String("types/Mutation/fields/updateExample")), jsii.String("appsync:GraphQL"))
```

## Methods

- `all(): IamResource // chainable` (static) — Generate the resource names that accepts all types: `*`.

- `custom(...arns: string[]): IamResource // chainable` (static) — Generate the resource names given custom arns.

  **Parameters**

  - `arns` — The custom arns that need to be permissioned.

- `ofType(type: string, ...fields: string[]): IamResource // chainable` (static) — Generate the resource names given a type and fields.

  **Parameters**

  - `type` — The type that needs to be allowed.
  - `fields` — The fields that need to be allowed, if empty grant permissions to ALL fields.

- `resourceArns(api: GraphqlApiBase): string[]` — Return the Resource ARN.

  **Parameters**

  - `api` — The GraphQL API to give permissions.
