AppSyncLambdaAuthorizerConfig

class aws_cdk.aws_appsync.AppSyncLambdaAuthorizerConfig(*, handler, results_cache_ttl=None, validation_regex=None)

Bases: object

Configuration for Lambda authorization in AppSync.

Note that you can only have a single AWS Lambda function configured to authorize your API.

Parameters:
  • handler (IFunction) – The authorizer lambda function.

  • results_cache_ttl (Optional[Duration]) – How long the results are cached. Disable caching by setting this to 0. Default: Duration.minutes(5)

  • validation_regex (Optional[str]) – A regular expression for validation of tokens before the Lambda function is called. Default: - no regex filter will be applied.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_lambda as lambda_
# handler: lambda.Function


iam_provider = appsync.AppSyncAuthProvider(
    authorization_type=appsync.AppSyncAuthorizationType.IAM
)

api_key_provider = appsync.AppSyncAuthProvider(
    authorization_type=appsync.AppSyncAuthorizationType.API_KEY
)

lambda_provider = appsync.AppSyncAuthProvider(
    authorization_type=appsync.AppSyncAuthorizationType.LAMBDA,
    lambda_authorizer_config=appsync.AppSyncLambdaAuthorizerConfig(
        handler=handler,
        results_cache_ttl=Duration.minutes(6),
        validation_regex="test"
    )
)

api = appsync.EventApi(self, "api",
    api_name="api",
    authorization_config=appsync.EventApiAuthConfig(
        # set auth providers
        auth_providers=[iam_provider, api_key_provider, lambda_provider
        ],
        connection_auth_mode_types=[appsync.AppSyncAuthorizationType.IAM
        ],
        default_publish_auth_mode_types=[appsync.AppSyncAuthorizationType.API_KEY
        ],
        default_subscribe_auth_mode_types=[appsync.AppSyncAuthorizationType.LAMBDA
        ]
    )
)

api.add_channel_namespace("default")

Attributes

handler

The authorizer lambda function.

See:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-lambdaauthorizerconfig.html

results_cache_ttl

How long the results are cached.

Disable caching by setting this to 0.

Default:

Duration.minutes(5)

validation_regex

A regular expression for validation of tokens before the Lambda function is called.

Default:
  • no regex filter will be applied.