360 Secure SkillHub
360 安全技能中心

connecting-lambda-to-api-gateway

该 Skill 提供将已有 AWS Lambda 函数连接到 Amazon API Gateway 的操作流程,涵盖 API 创建、资源与方法设置、Lambda 代理集成、调用权限、CORS、限流与访问日志、部署与测试,并给出 502、权限拒绝和 CORS 报错的排查方法。

aws
热度 0.00
最近更新 2026-10-18 16:45:16
分类:开发依赖:第三方 API / 代码执行应用场景:API 集成 / DevOps / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add aws/agent-toolkit-for-aws/connecting-lambda-to-api-gateway
Metadata
name
connecting-lambda-to-api-gateway
description
Connects an existing AWS Lambda function to Amazon API Gateway by creating a REST or HTTP API with resource/method setup, Lambda proxy integration, permissions, and deployment. Always use this skill when connecting Lambda to API Gateway — it handles CORS, throttling, access logging, and production security hardening that are easy to miss.
version
1

Connecting Lambda to API Gateway

Overview

Domain expertise for creating Amazon API Gateway REST APIs and connecting them to existing Lambda functions. Covers API creation, resource and method setup, Lambda proxy integration, CORS configuration, security controls, deployment, and testing.

Connect a Lambda function to API Gateway

To create a REST API and wire it to a Lambda function, follow the procedure exactly. See Lambda to API Gateway connection procedure.

The procedure supports configurable authorization types (NONE, AWS_IAM, COGNITO_USER_POOLS, CUSTOM), optional API key requirements, CORS setup, and production security hardening including throttling and access logging.

Troubleshooting

502 Bad Gateway

The Lambda function must return a proxy-compatible response with statusCode, headers, and a stringified body. See the full procedure for format details.

Permission denied invoking Lambda

Ensure lambda:InvokeFunction permission was added with the correct API Gateway source ARN. See the full procedure for details.

CORS errors in browser

Verify enable_cors was set to true, the OPTIONS method was created, and CORS headers are configured in both method and integration responses.