Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support VpcEndpointIds option for API Gateway #1033

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,10 @@ to change Zappa's behavior. Use these at your own risk!
}
}
],
"endpoint_configuration": ["EDGE", "REGIONAL", "PRIVATE"], // Specify APIGateway endpoint None (default) or list `EDGE`, `REGION`, `PRIVATE`
"endpoint_configuration": { // Optional endpoint configuration for API Gateway
"Types": ["EDGE", "REGIONAL", "PRIVATE"], // Specify APIGateway endpoint None (default) or list `EDGE`, `REGION`, `PRIVATE`
"VpcEndpointIds": [ "vpce-12345678" ] // VPC endpoint IDs for which to create public Route53 aliases (Supported for `PRIVATE` endpoint type only)
}
"exception_handler": "your_module.report_exception", // function that will be invoked in case Zappa sees an unhandled exception raised from your code
"exclude": ["file.gz", "tests"], // A list of filename patterns to exclude from the archive (see `fnmatch` module for patterns).
"exclude_glob": ["*.gz", "*.rar", "tests/**/*"], // A list of glob patterns to exclude from the archive. To exclude boto3 and botocore (available in an older version on Lambda), add "boto3*" and "botocore*".
Expand Down
8 changes: 7 additions & 1 deletion zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def get_stage_setting(stage, extended_stages=None):
if "delete_zip" in settings:
settings["delete_local_zip"] = settings.get("delete_zip")

# Backwards compatibility for endpoint_configuration property that was list instead of dict
# https://github.com/zappa/Zappa/issues/1024
if "endpoint_configuration" in settings and isinstance(settings["endpoint_configuration"], list):
settings["endpoint_configuration"] = {"Types": settings["endpoint_configuration"]}

settings.update(self.stage_config_overrides)

return settings
Expand Down Expand Up @@ -2952,7 +2957,8 @@ def touch_endpoint(self, endpoint_url):
# connect to the service, print a warning and let the user know
# to check it manually.
# See: https://github.com/Miserlou/Zappa/pull/1719#issuecomment-471341565
if "PRIVATE" in self.stage_config.get("endpoint_configuration", []):
endpoint_configuration = self.stage_config.get("endpoint_configuration", {})
if "Types" in endpoint_configuration and "PRIVATE" in endpoint_configuration["Types"]:
print(
click.style("Warning!", fg="yellow", bold=True) + " Since you're deploying a private API Gateway endpoint,"
" Zappa cannot determine if your function is returning "
Expand Down
13 changes: 10 additions & 3 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1696,12 +1696,19 @@ def create_api_gateway_routes(
if not description:
description = "Created automatically by Zappa."
restapi.Description = description
endpoint_configuration = [] if endpoint_configuration is None else endpoint_configuration

endpoint_configuration = (
{} if endpoint_configuration is None else endpoint_configuration
)
if self.boto_session.region_name == "us-gov-west-1":
endpoint_configuration.append("REGIONAL")
endpoint_configuration['Types'] = endpoint_configuration.get('Types', []) + ["REGIONAL"]
if endpoint_configuration:
endpoint = troposphere.apigateway.EndpointConfiguration()
endpoint.Types = list(set(endpoint_configuration))
# EndpointConfiguration property type has two properties: Types and VpcEndpointIds
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html
# https://github.com/zappa/Zappa/issues/1024
endpoint.Types = list(set(endpoint_configuration.get('Types', [])))
endpoint.VpcEndpointIds = endpoint_configuration.get('VpcEndpointIds', [])
restapi.EndpointConfiguration = endpoint
if self.apigateway_policy:
restapi.Policy = json.loads(self.apigateway_policy)
Expand Down
Loading