AppSync / Client / create_api

create_api#

AppSync.Client.create_api(**kwargs)#

Creates an Api object. Use this operation to create an AppSync API with your preferred configuration, such as an Event API that provides real-time message publishing and message subscriptions over WebSockets.

See also: AWS API Documentation

Request Syntax

response = client.create_api(
    name='string',
    ownerContact='string',
    tags={
        'string': 'string'
    },
    eventConfig={
        'authProviders': [
            {
                'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA',
                'cognitoConfig': {
                    'userPoolId': 'string',
                    'awsRegion': 'string',
                    'appIdClientRegex': 'string'
                },
                'openIDConnectConfig': {
                    'issuer': 'string',
                    'clientId': 'string',
                    'iatTTL': 123,
                    'authTTL': 123
                },
                'lambdaAuthorizerConfig': {
                    'authorizerResultTtlInSeconds': 123,
                    'authorizerUri': 'string',
                    'identityValidationExpression': 'string'
                }
            },
        ],
        'connectionAuthModes': [
            {
                'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA'
            },
        ],
        'defaultPublishAuthModes': [
            {
                'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA'
            },
        ],
        'defaultSubscribeAuthModes': [
            {
                'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA'
            },
        ],
        'logConfig': {
            'logLevel': 'NONE'|'ERROR'|'ALL'|'INFO'|'DEBUG',
            'cloudWatchLogsRoleArn': 'string'
        }
    }
)
Parameters:
  • name (string) –

    [REQUIRED]

    The name for the Api.

  • ownerContact (string) – The owner contact information for the Api.

  • tags (dict) –

    A map with keys of TagKey objects and values of TagValue objects.

    • (string) –

      The key for the tag.

      • (string) –

        The value for the tag.

  • eventConfig (dict) –

    The Event API configuration. This includes the default authorization configuration for connecting, publishing, and subscribing to an Event API.

    • authProviders (list) – [REQUIRED]

      A list of authorization providers.

      • (dict) –

        Describes an authorization provider.

        • authType (string) – [REQUIRED]

          The authorization type.

        • cognitoConfig (dict) –

          Describes an Amazon Cognito user pool configuration.

          • userPoolId (string) – [REQUIRED]

            The user pool ID.

          • awsRegion (string) – [REQUIRED]

            The Amazon Web Services Region in which the user pool was created.

          • appIdClientRegex (string) –

            A regular expression for validating the incoming Amazon Cognito user pool app client ID. If this value isn’t set, no filtering is applied.

        • openIDConnectConfig (dict) –

          Describes an OpenID Connect (OIDC) configuration.

          • issuer (string) – [REQUIRED]

            The issuer for the OIDC configuration. The issuer returned by discovery must exactly match the value of iss in the ID token.

          • clientId (string) –

            The client identifier of the relying party at the OpenID identity provider. This identifier is typically obtained when the relying party is registered with the OpenID identity provider. You can specify a regular expression so that AppSync can validate against multiple client identifiers at a time.

          • iatTTL (integer) –

            The number of milliseconds that a token is valid after it’s issued to a user.

          • authTTL (integer) –

            The number of milliseconds that a token is valid after being authenticated.

        • lambdaAuthorizerConfig (dict) –

          A LambdaAuthorizerConfig specifies how to authorize AppSync API access when using the AWS_LAMBDA authorizer mode. Be aware that an AppSync API can have only one Lambda authorizer configured at a time.

          • authorizerResultTtlInSeconds (integer) –

            The number of seconds a response should be cached for. The default is 0 seconds, which disables caching. If you don’t specify a value for authorizerResultTtlInSeconds, the default value is used. The maximum value is one hour (3600 seconds). The Lambda function can override this by returning a ttlOverride key in its response.

          • authorizerUri (string) – [REQUIRED]

            The Amazon Resource Name (ARN) of the Lambda function to be called for authorization. This can be a standard Lambda ARN, a version ARN ( .../v3), or an alias ARN.

            Note: This Lambda function must have the following resource-based policy assigned to it. When configuring Lambda authorizers in the console, this is done for you. To use the Command Line Interface (CLI), run the following:

            aws lambda add-permission --function-name "arn:aws:lambda:us-east-2:111122223333:function:my-function" --statement-id "appsync" --principal appsync.amazonaws.com --action lambda:InvokeFunction

          • identityValidationExpression (string) –

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

    • connectionAuthModes (list) – [REQUIRED]

      A list of valid authorization modes for the Event API connections.

      • (dict) –

        Describes an authorization configuration. Use AuthMode to specify the publishing and subscription authorization configuration for an Event API.

        • authType (string) – [REQUIRED]

          The authorization type.

    • defaultPublishAuthModes (list) – [REQUIRED]

      A list of valid authorization modes for the Event API publishing.

      • (dict) –

        Describes an authorization configuration. Use AuthMode to specify the publishing and subscription authorization configuration for an Event API.

        • authType (string) – [REQUIRED]

          The authorization type.

    • defaultSubscribeAuthModes (list) – [REQUIRED]

      A list of valid authorization modes for the Event API subscriptions.

      • (dict) –

        Describes an authorization configuration. Use AuthMode to specify the publishing and subscription authorization configuration for an Event API.

        • authType (string) – [REQUIRED]

          The authorization type.

    • logConfig (dict) –

      The CloudWatch Logs configuration for the Event API.

      • logLevel (string) – [REQUIRED]

        The type of information to log for the Event API.

      • cloudWatchLogsRoleArn (string) – [REQUIRED]

        The IAM service role that AppSync assumes to publish CloudWatch Logs in your account.

Return type:

dict

Returns:

Response Syntax

{
    'api': {
        'apiId': 'string',
        'name': 'string',
        'ownerContact': 'string',
        'tags': {
            'string': 'string'
        },
        'dns': {
            'string': 'string'
        },
        'apiArn': 'string',
        'created': datetime(2015, 1, 1),
        'xrayEnabled': True|False,
        'wafWebAclArn': 'string',
        'eventConfig': {
            'authProviders': [
                {
                    'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA',
                    'cognitoConfig': {
                        'userPoolId': 'string',
                        'awsRegion': 'string',
                        'appIdClientRegex': 'string'
                    },
                    'openIDConnectConfig': {
                        'issuer': 'string',
                        'clientId': 'string',
                        'iatTTL': 123,
                        'authTTL': 123
                    },
                    'lambdaAuthorizerConfig': {
                        'authorizerResultTtlInSeconds': 123,
                        'authorizerUri': 'string',
                        'identityValidationExpression': 'string'
                    }
                },
            ],
            'connectionAuthModes': [
                {
                    'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA'
                },
            ],
            'defaultPublishAuthModes': [
                {
                    'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA'
                },
            ],
            'defaultSubscribeAuthModes': [
                {
                    'authType': 'API_KEY'|'AWS_IAM'|'AMAZON_COGNITO_USER_POOLS'|'OPENID_CONNECT'|'AWS_LAMBDA'
                },
            ],
            'logConfig': {
                'logLevel': 'NONE'|'ERROR'|'ALL'|'INFO'|'DEBUG',
                'cloudWatchLogsRoleArn': 'string'
            }
        }
    }
}

Response Structure

  • (dict) –

    • api (dict) –

      The Api object.

      • apiId (string) –

        The Api ID.

      • name (string) –

        The name of the Api.

      • ownerContact (string) –

        The owner contact information for the Api

      • tags (dict) –

        A map with keys of TagKey objects and values of TagValue objects.

        • (string) –

          The key for the tag.

          • (string) –

            The value for the tag.

      • dns (dict) –

        The DNS records for the API. This will include an HTTP and a real-time endpoint.

        • (string) –

          • (string) –

      • apiArn (string) –

        The Amazon Resource Name (ARN) for the Api.

      • created (datetime) –

        The date and time that the Api was created.

      • xrayEnabled (boolean) –

        A flag indicating whether to use X-Ray tracing for this Api.

      • wafWebAclArn (string) –

        The Amazon Resource Name (ARN) of the WAF web access control list (web ACL) associated with this Api, if one exists.

      • eventConfig (dict) –

        The Event API configuration. This includes the default authorization configuration for connecting, publishing, and subscribing to an Event API.

        • authProviders (list) –

          A list of authorization providers.

          • (dict) –

            Describes an authorization provider.

            • authType (string) –

              The authorization type.

            • cognitoConfig (dict) –

              Describes an Amazon Cognito user pool configuration.

              • userPoolId (string) –

                The user pool ID.

              • awsRegion (string) –

                The Amazon Web Services Region in which the user pool was created.

              • appIdClientRegex (string) –

                A regular expression for validating the incoming Amazon Cognito user pool app client ID. If this value isn’t set, no filtering is applied.

            • openIDConnectConfig (dict) –

              Describes an OpenID Connect (OIDC) configuration.

              • issuer (string) –

                The issuer for the OIDC configuration. The issuer returned by discovery must exactly match the value of iss in the ID token.

              • clientId (string) –

                The client identifier of the relying party at the OpenID identity provider. This identifier is typically obtained when the relying party is registered with the OpenID identity provider. You can specify a regular expression so that AppSync can validate against multiple client identifiers at a time.

              • iatTTL (integer) –

                The number of milliseconds that a token is valid after it’s issued to a user.

              • authTTL (integer) –

                The number of milliseconds that a token is valid after being authenticated.

            • lambdaAuthorizerConfig (dict) –

              A LambdaAuthorizerConfig specifies how to authorize AppSync API access when using the AWS_LAMBDA authorizer mode. Be aware that an AppSync API can have only one Lambda authorizer configured at a time.

              • authorizerResultTtlInSeconds (integer) –

                The number of seconds a response should be cached for. The default is 0 seconds, which disables caching. If you don’t specify a value for authorizerResultTtlInSeconds, the default value is used. The maximum value is one hour (3600 seconds). The Lambda function can override this by returning a ttlOverride key in its response.

              • authorizerUri (string) –

                The Amazon Resource Name (ARN) of the Lambda function to be called for authorization. This can be a standard Lambda ARN, a version ARN ( .../v3), or an alias ARN.

                Note: This Lambda function must have the following resource-based policy assigned to it. When configuring Lambda authorizers in the console, this is done for you. To use the Command Line Interface (CLI), run the following:

                aws lambda add-permission --function-name "arn:aws:lambda:us-east-2:111122223333:function:my-function" --statement-id "appsync" --principal appsync.amazonaws.com --action lambda:InvokeFunction

              • identityValidationExpression (string) –

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

        • connectionAuthModes (list) –

          A list of valid authorization modes for the Event API connections.

          • (dict) –

            Describes an authorization configuration. Use AuthMode to specify the publishing and subscription authorization configuration for an Event API.

            • authType (string) –

              The authorization type.

        • defaultPublishAuthModes (list) –

          A list of valid authorization modes for the Event API publishing.

          • (dict) –

            Describes an authorization configuration. Use AuthMode to specify the publishing and subscription authorization configuration for an Event API.

            • authType (string) –

              The authorization type.

        • defaultSubscribeAuthModes (list) –

          A list of valid authorization modes for the Event API subscriptions.

          • (dict) –

            Describes an authorization configuration. Use AuthMode to specify the publishing and subscription authorization configuration for an Event API.

            • authType (string) –

              The authorization type.

        • logConfig (dict) –

          The CloudWatch Logs configuration for the Event API.

          • logLevel (string) –

            The type of information to log for the Event API.

          • cloudWatchLogsRoleArn (string) –

            The IAM service role that AppSync assumes to publish CloudWatch Logs in your account.

Exceptions

  • AppSync.Client.exceptions.BadRequestException

  • AppSync.Client.exceptions.ConcurrentModificationException

  • AppSync.Client.exceptions.UnauthorizedException

  • AppSync.Client.exceptions.InternalFailureException

  • AppSync.Client.exceptions.ServiceQuotaExceededException