Skip to main content

openapigateway

Create an Amazon API Gateway from an OpenAPI 3 Document.

PyPI PyPI - Python Version Code style: black PyPI - License

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

Installation

pip install openapigateway

Usage

Example 1: API backed by Lambda Function

openapi.yaml:

[...]
paths:
  /pets:
    get:
      summary: List all pets
      responses:
        [...]
      x-amazon-apigateway-integration:
        uri: "${API_LAMBDA_ARN}"
        type: "AWS_PROXY"
        httpMethod: "POST"
        connectionType: "INTERNET"
        payloadFormatVersion: "2.0"
      x-amazon-apigateway-request-validator:
        validateRequestBody: true
        validateRequestParameters: true
[...]

open_api_stack.py:

from aws_cdk import core, aws_iam as iam, aws_lambda as _lambda
from openapigateway import OpenApiGateway


class OpenApiStack(core.Stack):
    def __init__(
        self, scope: core.Construct, construct_id: str, **kwargs
    ) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # function that handles api request(s)
        api_lambda = _lambda.Function([...])

        # create api from openapi document and replace params
        openapi = OpenApiGateway(
            self,
            "OpenAPI Gateway",
            openapi_path="openapi.yaml",
            param_value_dict={"API_LAMBDA_ARN": api_lambda.function_arn},
            fail_on_warnings=True,
        )

        # grant HttpApi permission to invoke api lambda function
        api_lambda.add_permission(
            f"Invoke By {openapi.http_api.node.id} Permission",
            principal=iam.ServicePrincipal("apigateway.amazonaws.com"),
            action="lambda:InvokeFunction",
            source_arn=openapi.http_api_arn,
        )

Documentation

Development setup

optional: use virtualenv

# create virtualenv on MacOS and Linux
python3 -m venv .venv
# activate virtualenv
source .venv/bin/activate

install dependencies

To install this package, along with the tools you need to develop and publish it, run the following:

pip install -e ".[dev]"

Contributing

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

License

MIT

Metadata

Release files for openapigateway 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openapigateway 0.2.1
File Size Uploaded Provenance Actions
openapigateway-0.2.1.tar.gz 5.2 kB Without provenance Details for openapigateway-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openapigateway 0.2.1
File Interpreter ABI Platform Actions
openapigateway-0.2.1-py3-none-any.whl Python 3 none any Details for openapigateway-0.2.1-py3-none-any.whl

Total release size: 10.8 kB

Release files / openapigateway-0.2.1.tar.gz

Download URL openapigateway-0.2.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ef23f36ef34fb8f8cb9755bbef3b670ec135331013968c4ff8bb680e7faf6514
BLAKE2b-256 checksum
How to use checksums
d229c6ab8cb1525aabf938e24ecef85ebe7d0669a5b19c0afdc65388ba709466
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

Release files / openapigateway-0.2.1-py3-none-any.whl

Download URL openapigateway-0.2.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
897a88a95e52252e33a66d40ad2feb665a4c6d650d05e1776d5c6cc3327e2050
BLAKE2b-256 checksum
How to use checksums
2a5966a8a882596b706d76a51701615148f7b8ffca9dfc536bfb4251878a38eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

Security for openapigateway 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page