AuthorizationType Enum
enum with all possible values for AppSync authorization type.
Example
ts
import * as iam from 'aws-cdk-lib/aws-iam';
import * as appsync from 'aws-cdk-lib/aws-appsync';
const api = appsync.GraphqlApi.fromGraphqlApiAttributes(this, 'ImportedAPI', {
graphqlApiId: '<api-id>',
graphqlApiArn: '<api-arn>',
graphQLEndpointArn: '<api-endpoint-arn>',
visibility: appsync.Visibility.GLOBAL,
modes: [appsync.AuthorizationType.IAM],
});
const rule = new events.Rule(this, 'Rule', { schedule: events.Schedule.rate(cdk.Duration.minutes(1)), });
const role = new iam.Role(this, 'Role', { assumedBy: new iam.ServicePrincipal('events.amazonaws.com') });
// allow EventBridge to use the `publish` mutation
api.grantMutation(role, 'publish');
rule.addTarget(new targets.AppSync(api, {
graphQLOperation: 'mutation Publish($message: String!){ publish(message: $message) { message } }',
variables: events.RuleTargetInput.fromObject({
message: 'hello world',
}),
eventRole: role
}));
python
import aws_cdk.aws_iam as iam
import aws_cdk.aws_appsync as appsync
api = appsync.GraphqlApi.from_graphql_api_attributes(self, "ImportedAPI",
graphql_api_id="<api-id>",
graphql_api_arn="<api-arn>",
graph_ql_endpoint_arn="<api-endpoint-arn>",
visibility=appsync.Visibility.GLOBAL,
modes=[appsync.AuthorizationType.IAM]
)
rule = events.Rule(self, "Rule", schedule=events.Schedule.rate(cdk.Duration.minutes(1)))
role = iam.Role(self, "Role", assumed_by=iam.ServicePrincipal("events.amazonaws.com"))
# allow EventBridge to use the `publish` mutation
api.grant_mutation(role, "publish")
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"
}),
event_role=role
))
java
import software.amazon.awscdk.services.iam.*;
import software.amazon.awscdk.services.appsync.*;
IGraphqlApi api = GraphqlApi.fromGraphqlApiAttributes(this, "ImportedAPI", GraphqlApiAttributes.builder()
.graphqlApiId("<api-id>")
.graphqlApiArn("<api-arn>")
.graphQLEndpointArn("<api-endpoint-arn>")
.visibility(Visibility.GLOBAL)
.modes(List.of(AuthorizationType.IAM))
.build());
Rule rule = Rule.Builder.create(this, "Rule").schedule(Schedule.rate(Duration.minutes(1))).build();
Role role = Role.Builder.create(this, "Role").assumedBy(new ServicePrincipal("events.amazonaws.com")).build();
// allow EventBridge to use the `publish` mutation
api.grantMutation(role, "publish");
rule.addTarget(AppSync.Builder.create(api)
.graphQLOperation("mutation Publish($message: String!){ publish(message: $message) { message } }")
.variables(RuleTargetInput.fromObject(Map.of(
"message", "hello world")))
.eventRole(role)
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.AppSync;
var api = GraphqlApi.FromGraphqlApiAttributes(this, "ImportedAPI", new GraphqlApiAttributes {
GraphqlApiId = "<api-id>",
GraphqlApiArn = "<api-arn>",
GraphQLEndpointArn = "<api-endpoint-arn>",
Visibility = Visibility.GLOBAL,
Modes = new [] { AuthorizationType.IAM }
});
var rule = new Rule(this, "Rule", new RuleProps { Schedule = Schedule.Rate(Duration.Minutes(1)) });
var role = new Role(this, "Role", new RoleProps { AssumedBy = new ServicePrincipal("events.amazonaws.com") });
// allow EventBridge to use the `publish` mutation
api.GrantMutation(role, "publish");
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" }
}),
EventRole = role
}));
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
api := appsync.GraphqlApi_FromGraphqlApiAttributes(this, jsii.String("ImportedAPI"), &GraphqlApiAttributes{
GraphqlApiId: jsii.String("<api-id>"),
GraphqlApiArn: jsii.String("<api-arn>"),
GraphQLEndpointArn: jsii.String("<api-endpoint-arn>"),
Visibility: appsync.Visibility_GLOBAL,
Modes: []AuthorizationType{
appsync.AuthorizationType_IAM,
},
})
rule := events.NewRule(this, jsii.String("Rule"), &RuleProps{
Schedule: events.Schedule_Rate(cdk.Duration_Minutes(jsii.Number(1))),
})
role := iam.NewRole(this, jsii.String("Role"), &RoleProps{
AssumedBy: iam.NewServicePrincipal(jsii.String("events.amazonaws.com")),
})
// allow EventBridge to use the `publish` mutation
api.GrantMutation(role, jsii.String("publish"))
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"),
}),
EventRole: role,
}))
Members
| Member | Description |
|---|---|
API_KEY | API Key authorization type. |
IAM | AWS IAM authorization type. |
USER_POOL | Cognito User Pool authorization type. |
OIDC | OpenID Connect authorization type. |
LAMBDA | Lambda authorization type. |
Referenced by
AuthorizationMode.authorizationTypeauthorization_typeauthorizationTypeAuthorizationTypeAuthorizationTypeGraphqlApi.modesmodesmodesModesModesGraphqlApiAttributes.modesmodesmodesModesModesGraphqlApiBase.modesmodesmodesModesModesIGraphqlApi.modesmodesmodesModesModes