openapigateway
Create an Amazon API Gateway from an OpenAPI 3 Document.
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)
api_lambda = _lambda.Function([...])
openapi = OpenApiGateway(
self,
"OpenAPI Gateway",
openapi_path="openapi.yaml",
param_value_dict={"API_LAMBDA_ARN": api_lambda.function_arn},
fail_on_warnings=True,
)
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,
)
Development setup
optional: use virtualenv
python3 -m venv .venv
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
- Fork this repository
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
License
MIT