openapigateway package

Submodules

openapigateway.constructs module

Constructs that facilitate the creation of Amazon API Gateway HttpApi Resources from OpenAPI 3 Documents.

class openapigateway.constructs.OpenApiGateway(*args, **kwargs)

Bases: aws_cdk.core.Construct

AWS CDK Construct that creates an Amazon API Gateway HttpApi based on a parameterized OpenAPI 3 Document.

Create HttpApi from parameterized OpenAPI 3 Document.

Parameters
  • scope (aws_cdk.core.Construct) – The construct within which this construct is defined.

  • id (str) – An identifier that must be uniqie within this scope.

  • openapi_path (str) – Path to the OpenAPI 3 Document that serves as specification to create the API Gateway HttpApi. JSON and YAML files are supported.

  • param_value_dict (dict, optional) – Dictionary used to replace some parameters in the OpenAPI 3 Document during build time. This is necessary to reference AWS resources that don’t yet exist when the OpenAPI Document is written. ${<key>} in the OpenAPI Document gets replaced by <value> from this dictionary. For example: {“API_LAMBDA_ARN”: api_lambda.function_arn} would replace ${API_LAMBDA_ARN} in the OpenAPI Document by the ARN of an api_lambda lambda function.

  • fail_on_warnings (bool, optional) – Wheter to rollback the API creation when a warning is encountered, default is False.

Examples

>>> api_lambda = _lambda()
>>> OpenApiGateway(
>>>     self,
>>>     "OpenAPI Gateway",
>>>     openapi_path="openapi.json",
>>>     param_value_dict={
>>>         "API_LAMBDA_ARN": api_lambda.function_arn
>>>     },
>>>     fail_on_warnings=True
>>> )
property http_api

The HttpApi created by this construct.

Returns

HttpApi resource that has been created by this construct.

Return type

aws_cdk.aws_apigatewayv2.HttpApi

property http_api_arn

The ARN of the HttpApi created by this construct.

Returns

ARN of the HttpApi resource that has been created by this construct.

Return type

str

openapigateway.constructs.json_or_yaml_to_dict(string: str) → dict

Parse JSON/YAML string to dict.

Parameters

string (str) – String containing a valid JSON or YAML document.

Returns

Dictionary of the parsed string.

Return type

dict

Raises

ValueError – If the string can neither be parsed as JSON nor YAML.

Module contents

openapigateway

AWS CDK Construct that creates an Amazon API Gateway HttpApi based on a parameterized OpenAPI 3 Document.