Install & Compatibility
Where this runs
tested against v1.204.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 70MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 8.8s · import 0.000s · 71MB
73MB installed
● package 73MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
aws_apigateway
✓ from aws_cdk import aws_apigateway as apigw
✗ from aws_cdk.aws_apigateway import RestApi
Commonly imported with an alias for brevity and to distinguish from V2 imports.
RestApi
✓ apigw.RestApi(...)
✗ RestApi(...)
After importing `aws_cdk.aws_apigateway as apigw`, constructs are accessed via the alias.
This quickstart defines a simple AWS CDK v1 stack that creates an API Gateway REST API with a single GET endpoint. This endpoint is integrated with a Python Lambda function that returns a 'Hello from Lambda!' message. It demonstrates basic API Gateway and Lambda integration within the CDK v1 framework. Remember to run `cdk deploy` after `app.synth()` to provision resources.
import os
from aws_cdk import (
core,
aws_apigateway as apigw,
aws_lambda as lambda_,
)
class MyApiStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Define a Lambda function to integrate with API Gateway
hello_function = lambda_.Function(
self, "HelloFunction",
runtime=lambda_.Runtime.PYTHON_3_9,
handler="index.handler",
code=lambda_.Code.from_inline("def handler(event, context): return {'statusCode': 200, 'body': 'Hello from Lambda!'}")
)
# Create a REST API
api = apigw.RestApi(
self, "MySimpleApi",
rest_api_name="MySimpleApi",
description="A simple API Gateway example backed by Lambda.",
deploy=True, # Automatically creates a default deployment and stage
deploy_options=apigw.StageOptions(
stage_name="dev"
)
)
# Add a GET method to the root path, integrating with the Lambda function
api.root.add_method(
"GET",
apigw.LambdaIntegration(hello_function)
)
app = core.App()
MyApiStack(app, "MyApiGatewayStack")
app.synth()
Debug
Known issues
breakingThis library (`aws-cdk.aws-apigateway`) is part of AWS CDK v1. AWS CDK v2 is a major rewrite with different package structures, module names (e.g., `aws_cdk.aws_apigateway` is now `aws_cdk_lib.aws_apigateway`), and updated constructs. Migrating from v1 to v2 requires significant code changes.fixFor new projects, consider using CDK v2 (install `aws-cdk-lib`). For existing v1 projects, follow the official AWS CDK v2 migration guide to upgrade components gradually or maintain a v1 environment.
affects: All v1 versions (1.x.x) when migrating to v2 (2.x.x)
gotchaAll Constructs within a given scope (e.g., a Stack or another Construct) must have a unique ID. Reusing IDs will lead to synthesis or deployment errors.fixEnsure that the `id` argument for each Construct instantiation is unique within its parent scope. For example, `apigw.RestApi(self, 'MyApi')` and `apigw.RestApi(self, 'AnotherApi')` are valid, but two `RestApi(self, 'MyApi')` calls in the same scope are not.
affects: All v1 versions
gotchaAPI Gateway requires explicit deployment and stage creation to make the API accessible. While `deploy=True` on `apigw.RestApi` creates a default deployment and stage, complex scenarios with multiple stages, custom stage variables, or external deployment triggers require manual `apigw.Deployment` and `apigw.Stage` constructs.fixFor simple APIs, use `deploy=True` on `apigw.RestApi`. For advanced stage management, explicitly define `apigw.Deployment(self, 'ApiDeployment', api=api)` and `apigw.Stage(self, 'ProdStage', deployment=deployment, stage_name='prod')`.
affects: All v1 versions
gotchaWhen integrating API Gateway with other AWS services (e.g., Lambda, SQS, Kinesis), ensure that the API Gateway execution role or the integrated resource itself has the necessary IAM permissions. While Lambda integrations often handle this automatically, other integrations might require manual IAM policy attachments.fixExplicitly grant permissions using `iam.Role` and `iam.PolicyStatement` constructs. For example, if integrating with SQS, the API Gateway execution role needs `sqs:SendMessage` permissions to the target queue.
affects: All v1 versions
Upgrade
Version history
1.204.0latest on PyPI · released Jun 19, 2023
Audit
Dependencies
aws-cdk.corerequiredCore CDK library, required for all CDK applications.