# AuthorizationConfig

Configuration of the API authorization modes.

- Source: [`aws-appsync/lib/graphqlapi.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-appsync/lib/graphqlapi.ts#L176)
- Type last changed: v2.60.0 · 12 Jan 2023

## Example

TypeScript:

```ts
import * as appsync from 'aws-cdk-lib/aws-appsync';

const api = new appsync.GraphqlApi(this, 'api', {
  name: 'api',
  definition: appsync.Definition.fromFile('schema.graphql'),
  authorizationConfig: {
    defaultAuthorization: { authorizationType: appsync.AuthorizationType.IAM }
  },
});

const rule = new events.Rule(this, 'Rule', {
  schedule: events.Schedule.rate(cdk.Duration.hours(1)),
});

rule.addTarget(new targets.AppSync(api, {
  graphQLOperation: 'mutation Publish($message: String!){ publish(message: $message) { message } }',
  variables: events.RuleTargetInput.fromObject({
    message: 'hello world',
  }),
}));
```

Python:

```python
import aws_cdk.aws_appsync as appsync

api = appsync.GraphqlApi(self, "api",
    name="api",
    definition=appsync.Definition.from_file("schema.graphql"),
    authorization_config=appsync.AuthorizationConfig(
        default_authorization=appsync.AuthorizationMode(authorization_type=appsync.AuthorizationType.IAM)
    )
)

rule = events.Rule(self, "Rule",
    schedule=events.Schedule.rate(cdk.Duration.hours(1))
)

rule.add_target(targets.AppSync(api,
    graph_ql_operation="mutation Publish($message: String!){ publish(message: $message) { message } }",
    variables=events.RuleTargetInput.from_object({
        "message": "hello world"
    })
))
```

Java:

```java
import software.amazon.awscdk.services.appsync.*;

GraphqlApi api = GraphqlApi.Builder.create(this, "api")
        .name("api")
        .definition(Definition.fromFile("schema.graphql"))
        .authorizationConfig(AuthorizationConfig.builder()
                .defaultAuthorization(AuthorizationMode.builder().authorizationType(AuthorizationType.IAM).build())
                .build())
        .build();

Rule rule = Rule.Builder.create(this, "Rule")
        .schedule(Schedule.rate(Duration.hours(1)))
        .build();

rule.addTarget(AppSync.Builder.create(api)
        .graphQLOperation("mutation Publish($message: String!){ publish(message: $message) { message } }")
        .variables(RuleTargetInput.fromObject(Map.of(
                "message", "hello world")))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.AppSync;

var api = new GraphqlApi(this, "api", new GraphqlApiProps {
    Name = "api",
    Definition = Definition.FromFile("schema.graphql"),
    AuthorizationConfig = new AuthorizationConfig {
        DefaultAuthorization = new AuthorizationMode { AuthorizationType = AuthorizationType.IAM }
    }
});

var rule = new Rule(this, "Rule", new RuleProps {
    Schedule = Schedule.Rate(Duration.Hours(1))
});

rule.AddTarget(new AppSync(api, new AppSyncGraphQLApiProps {
    GraphQLOperation = "mutation Publish($message: String!){ publish(message: $message) { message } }",
    Variables = RuleTargetInput.FromObject(new Dictionary<string, string> {
        { "message", "hello world" }
    })
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"

api := appsync.NewGraphqlApi(this, jsii.String("api"), &GraphqlApiProps{
	Name: jsii.String("api"),
	Definition: appsync.Definition_FromFile(jsii.String("schema.graphql")),
	AuthorizationConfig: &AuthorizationConfig{
		DefaultAuthorization: &AuthorizationMode{
			AuthorizationType: appsync.AuthorizationType_IAM,
		},
	},
})

rule := events.NewRule(this, jsii.String("Rule"), &RuleProps{
	Schedule: events.Schedule_Rate(cdk.Duration_Hours(jsii.Number(1))),
})

rule.AddTarget(targets.NewAppSync(api, &AppSyncGraphQLApiProps{
	GraphQLOperation: jsii.String("mutation Publish($message: String!){ publish(message: $message) { message } }"),
	Variables: events.RuleTargetInput_FromObject(map[string]*string{
		"message": jsii.String("hello world"),
	}),
}))
```

## Properties

- `additionalAuthorizationModes`: [AuthorizationMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AuthorizationMode.html)[] — Additional authorization modes.

  **Default:** No other modes

- `defaultAuthorization`: [AuthorizationMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.AuthorizationMode.html) — Optional authorization configuration.

  **Default:** API Key authorization
