Creating API Gateway Stage
AWSOfficialPublished by AWS
- Skill
- Workflow
- Cloud and DevOps
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured procedure for creating and configuring API Gateway stages. It automates the setup of essential infrastructure components including CloudWatch logging, X-Ray tracing, WAF integration, and necessary IAM roles. The workflow ensures that API stages are initialized with consistent settings for logging levels, metrics, and throttling limits, following standard AWS configuration patterns.
What it does
- Validates the existence of REST API and deployment resources
- Configures CloudWatch logging roles and permissions for API Gateway
- Enables detailed CloudWatch metrics and execution logging
- Integrates WAF web ACLs for enhanced security
- Sets up throttling rate and burst limits for API stages
- Configures X-Ray tracing for request monitoring
When to use it
- When deploying a new REST API stage to environments like dev, test, or prod
- When standardizing logging and monitoring configurations across API stages
- When implementing security controls like WAF and throttling for API endpoints
- When setting up the required IAM infrastructure for API Gateway logging
Advantages
- Ensures consistent configuration of logging and security across environments
- Automates the creation and attachment of required IAM roles
- Provides built-in validation for API Gateway resources before deployment
- Simplifies the setup of complex monitoring and tracing features
Usage examples
- “Create a new dev stage for my API with ID abc123xyz and deployment ID dep987.”
- The agent initiates the workflow to validate the API and deployment, checks for existing IAM roles, and creates the dev stage with default logging and security settings.
- “Set up a production stage for API xyz789 with custom throttling limits.”
- The agent executes the deployment procedure, applying the specified rate and burst limits while ensuring WAF and CloudWatch logging are correctly configured.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/aws/creating-api-gateway-stage/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip creating-api-gateway-stage.zip -d .agents/skills
Documentation by AWS
Creating an API Gateway Stage
Overview
Domain expertise for creating and configuring API Gateway stages with comprehensive logging, monitoring, security, and throttling controls. Covers CloudWatch logging setup, X-Ray tracing, WAF web ACL association, method-level configuration, and authorization options.
Create an API Gateway stage
To create a fully configured API Gateway stage with logging, throttling, WAF, and authorization, follow the procedure exactly. See API Gateway stage creation procedure.
Troubleshooting
CloudWatch logs not appearing
Verify the CloudWatch role permissions, log group existence, and that logging is enabled at both stage and method levels. See the full procedure for details.
Stage creation fails
Check REST API ID, deployment ID, IAM permissions, and stage naming conventions.
WAF blocking legitimate requests
Review WAF logs, adjust rules or add exceptions, and consider count mode for testing.
Files
- ATTRIBUTION.mdAdded by AutoGineer942 B
- LICENSELicence file added by AutoGineer9.9 KiB
- NOTICELicence file added by AutoGineer67 B
- SKILL.md1.3 KiB
- references/create-api-gateway-stage.md13.9 KiB
references/create-api-gateway-stage.md
Create API Gateway Stage with Logging Configuration
Overview
This SOP creates an API Gateway stage with comprehensive logging configuration, stage variables, and necessary IAM roles. It follows AWS best practices for API Gateway stage setup including CloudWatch logging, X-Ray tracing, and proper access logging.
Parameters
rest_api_id (required): The ID of the REST API for which to create the stage
stage_name (required): The name of the stage (e.g., dev, test, prod)
deployment_id (required): The deployment ID to associate with the stage
log_level (optional, default: "INFO"): The logging level for execution logs (OFF, ERROR, INFO)
metrics_enabled (optional, default: "true"): Whether to enable detailed CloudWatch metrics
data_trace_enabled (optional, default: "false"): Whether to enable data tracing for all methods
throttling_rate_limit (optional, default: "1000"): The throttling rate limit per second
throttling_burst_limit (optional, default: "2000"): The throttling burst limit
enable_waf (optional, default: "true"): Whether to create and associate a WAF web ACL for security
Steps
1. Verify Dependencies
Check for required tools and warn the user if any are missing.
Constraints:
You MUST verify the following tools are available in your context:
call_awsYou MUST ONLY check for tool existence and MUST NOT attempt to run the tools because running tools during verification could cause unintended side effects, consume resources unnecessarily, or trigger actions before the user is ready
You MUST inform the user about any missing tools with a clear message
You MUST ask if the user wants to proceed anyway despite missing tools
You MUST respect the user's decision to proceed or abort
2. Validate API Gateway Resources
Verify that the specified REST API and deployment exist.
Constraints:
You MUST inform the customer that you are validating the REST API and deployment existence
You MUST use
call_awsto describe the REST API using:aws apigateway get-rest-api --rest-api-id {rest_api_id}You MUST use
call_awsto verify the deployment exists using:aws apigateway get-deployment --rest-api-id {rest_api_id} --deployment-id {deployment_id}You MUST stop execution and inform the user if either resource does not exist
You MUST NEVER use positional arguments that require local files or filesystem access
3. Check Existing CloudWatch Logs IAM Role
Verify if API Gateway has the necessary IAM role for CloudWatch logging.
Constraints:
You MUST inform the customer that you are checking for existing CloudWatch logging IAM role configuration
You MUST use
call_awsto check the account settings:aws apigateway get-accountYou MUST examine the
cloudwatchRoleArnfield in the responseYou SHOULD note if the role is already configured or needs to be created
4. Create CloudWatch Logs IAM Role (if needed)
Create the IAM role for API Gateway CloudWatch logging if it doesn't exist.
Constraints:
You MUST inform the customer that you are creating the CloudWatch logs IAM role if none exists
You MUST create the role with the following trust policy allowing apigateway.amazonaws.com to assume it:
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"apigateway.amazonaws.com"},"Action":"sts:AssumeRole"}]}You MUST use
call_awswith:aws iam create-role --role-name APIGatewayCloudWatchLogsRole --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"apigateway.amazonaws.com"},"Action":"sts:AssumeRole"}]}'You MUST attach the AWS managed policy for CloudWatch logs:
aws iam attach-role-policy --role-name APIGatewayCloudWatchLogsRole --policy-arn arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogsYou MUST NEVER use passwords and always rely on IAM roles and policies for authentication
You MUST skip this step if a CloudWatch role is already configured
5. Update Account Settings with CloudWatch Role
Configure the API Gateway account to use the CloudWatch logs role.
Constraints:
You MUST inform the customer that you are updating account settings to use the CloudWatch role
You MUST use
call_awsto update account settings:aws apigateway update-account --patch-operationsYou MUST set the cloudwatchRoleArn to the created or existing role ARN
You MUST handle cases where the role is already set appropriately
6. Create CloudWatch Log Group
Create a dedicated log group for the API Gateway stage.
Constraints:
You MUST inform the customer that you are creating a CloudWatch log group for the stage
You MUST use a naming convention like:
/aws/apigateway/{rest_api_id}/{stage_name}You MUST use
call_awswith:aws logs create-log-group --log-group-nameYou SHOULD handle cases where the log group already exists gracefully
7. Configure Log Group Retention Policy
Set the retention policy for the CloudWatch log group to manage log lifecycle.
Constraints:
You MUST inform the customer that you are configuring the retention policy for the CloudWatch log group
You MUST set retention period using:
aws logs put-retention-policy --log-group-name --retention-in-days 14You MUST handle cases where retention is already set appropriately
8. Create API Gateway Stage
Create the API Gateway stage with data tracing configuration.
Constraints:
You MUST inform the customer that you are creating the API Gateway stage with logging and monitoring configuration
You MUST use
call_awsto create the stage with all configurations:aws apigateway create-stage --rest-api-id {rest_api_id} --stage-name {stage_name} --deployment-id {deployment_id} --description {stage_description} --variables {environment-variables} --tracing-enabledYou MUST include stage variables for environment-specific configuration
You MUST enable CloudWatch logging with specified log level
You MUST enable X-Ray tracing for distributed tracing capabilities
You MUST configure data tracing using the data_trace_enabled parameter:
--data-trace-enabled {data_trace_enabled}You MUST NEVER configure throttling, access-logs and method settings in this step, and do it in the next step
9. Configure Throttling limits and caching
Update the API Gateway stage with comprehensive configuration.
Constraints:
You MUST inform the customer that you are configuring throttling limits the API Gateway stage
You MUST set appropriate caching and throttling settings per method
You MUST use
call_awsto configure API Gateway Stageaws apigateway update-stage --rest-api-id {api_gateway_id} --stage-name {stage_name} --patch-operations op=replace,path=/*/*/throttling/rateLimit,value={throttling_rate_limit} op=replace,path=/*/*/throttling/burstLimit,value={throttling_burst_limit}You MUST set up throttling limits for rate protection including throttlingRateLimit and throttlingBurstLimit
You MUST include stage variables for environment-specific configuration
You MUST use SecretsManager for any sensitive configuration values
You MUST NEVER prompt for or use passwords directly
10. Configure Method-Level Logging
Set up method-level access and execution logging configuration for better granularity.
Constraints:
You MUST inform the customer that you are configuring method-level logging settings
You MUST use update access logging and execution logging separately
You MUST configure logging for all HTTP methods (/) unless specified otherwise
You MUST use
call_awsto update method settings for access logging usingaws apigateway update-stage --rest-api-id {api_gateway_id} --stage-name {stage_name} --patch-operations '[{"op":"replace","path":"/accessLogSettings/destinationArn","value":{log_group_arn}},{"op":"replace","path":"/accessLogSettings/format","value":"$context.requestId $context.ip $context.caller $context.user [$context.requestTime] \"$context.httpMethod $context.resourcePath $context.protocol\" $context.status $context.error.message $context.responseLength $context.requestTime $context.xrayTraceId"}]'You MUST use
call_awsto update method settings for execution logging usingaws apigateway update-stage --rest-api-id {api_gateway_id} --stage-name {stage_name} --patch-operations '[{"op":"replace","path":"/*/*/logging/loglevel","value":"INFO"},{"op":"replace","path":"/*/*/metrics/enabled","value":"true"}]'
11. Create and Associate WAF Web ACL (if enabled)
Create a WAF web ACL with basic security rules and associate it with the API Gateway stage for defense in depth.
Constraints:
You MUST inform the customer that you are creating a WAF web ACL for API security if enable_waf is true
You MUST create a WAFv2 web ACL with basic managed rules using:
aws wafv2 create-web-acl --name {api_name}-{stage_name}-waf --scope REGIONAL --default-action Allow={} --rulesYou MUST include AWS managed rule groups for common protections: AWSManagedRulesCommonRuleSet, AWSManagedRulesKnownBadInputsRuleSet
You MUST add rate limiting rule to prevent abuse:
aws wafv2 create-web-aclwith rate-based ruleYou MUST associate the web ACL with the API Gateway stage using:
aws wafv2 associate-web-acl --web-acl-arn {web_acl_arn} --resource-arn arn:aws:apigateway:{region}::/restapis/{rest_api_id}/stages/{stage_name}You MUST skip this step if enable_waf is false
You SHOULD inform the user about WAF costs and monitoring
12. Configure Authorization
Ask the user about authorization requirements and provide configuration guidance.
Constraints:
You MUST ask the user: "Do you want to configure authorization for this API Gateway stage? Options: NONE (no auth), IAM (AWS IAM), API_KEYS (require API keys), LAMBDA (Lambda authorizer), or CUSTOM (custom authorizer)?"
You MUST provide setup instructions based on their choice:
For NONE: Inform that the API will be publicly accessible
For IAM: Provide guidance on setting up IAM policies and roles
For API_KEYS: Show how to create and manage API keys
For LAMBDA: Provide instructions for creating Lambda authorizer functions
For CUSTOM: Provide guidance for custom authorization implementations
You SHOULD recommend using IAM, API_KEYS, or LAMBDA for production environments
You MUST inform the user that authorization can be configured later if they choose NONE
13. Test Stage Configuration
Validate that the stage has been created successfully with proper configuration.
Constraints:
You MUST inform the customer that you are validating the stage configuration
You MUST use
call_awsto get stage details:aws apigateway get-stage --rest-api-id {rest_api_id} --stage-name {stage_name}You MUST verify all logging configurations are properly applied
You MUST check that CloudWatch logs are being generated
You MUST verify WAF association if enabled using:
aws wafv2 get-web-acl-for-resource --resource-arn arn:aws:apigateway:{region}::/restapis/{rest_api_id}/stages/{stage_name}You MUST provide the stage URL for testing
14. Provide Testing Instructions
Provide comprehensive examples for testing of new API Gateway stage.
Constraints:
You MUST provide AWS CLI commands for testing the API Gateway stage
You MUST show how to monitor logs and metrics in CloudWatch
You MUST explain how to use stage variables in applications
You MUST provide troubleshooting guidance for common issues
Examples
AWS CLI Commands for Testing
# Test the API Gateway stage
aws apigateway test-invoke-method --rest-api-id {rest_api_id} --stage-name {stage_name} --method GET --path-with-query-string /
# Get stage information
aws apigateway get-stage --rest-api-id {rest_api_id} --stage-name {stage_name}
# View CloudWatch logs
aws logs describe-log-streams --log-group-name /aws/apigateway/{rest_api_id}/{stage_name}
# Get stage metrics
aws cloudwatch get-metric-statistics --namespace AWS/ApiGateway --metric-name Count --dimensions Name=ApiName,Value={api_name} Name=Stage,Value={stage_name} --start-time 2024-01-01T00:00:00Z --end-time 2024-01-01T23:59:59Z --period 3600 --statistics Sum
# Check WAF web ACL association (if WAF is enabled)
aws wafv2 get-web-acl-for-resource --resource-arn arn:aws:apigateway:{region}::/restapis/{rest_api_id}/stages/{stage_name}
# Monitor WAF metrics
aws cloudwatch get-metric-statistics --namespace AWS/WAFV2 --metric-name AllowedRequests --dimensions Name=WebACL,Value={web_acl_name} Name=Region,Value={region} --start-time 2024-01-01T00:00:00Z --end-time 2024-01-01T23:59:59Z --period 3600 --statistics SumTroubleshooting
CloudWatch Logs Not Appearing
If logs are not appearing in CloudWatch:
Verify the CloudWatch role has correct permissions
Check that the log group exists and has proper retention settings
Ensure the API Gateway account settings point to the correct IAM role
Verify that logging is enabled at both stage and method levels
Stage Creation Fails
If stage creation fails:
Verify the REST API ID and deployment ID are correct
Check that you have sufficient IAM permissions
Ensure the stage name follows AWS naming conventions
Verify that throttling limits are within account limits
High Latency or Errors
If experiencing performance issues:
Check CloudWatch metrics for error rates and latencies
Review X-Ray traces for bottlenecks
Verify caching settings are appropriate
Check throttling configuration and adjust if needed
WAF Issues
If WAF is blocking legitimate requests:
Review WAF logs in CloudWatch to identify blocked requests
Adjust WAF rules or add exceptions for legitimate traffic
Monitor WAF metrics for blocked vs allowed requests
Consider using WAF in count mode initially for testing
Authorization Issues
If experiencing authorization problems:
Verify IAM policies have correct permissions for AWS_IAM auth
Check Cognito user pool configuration for COGNITO_USER_POOLS auth
Validate Lambda authorizer function for CUSTOM auth
Test authorization independently before API Gateway integration
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- AWS
- Publisher
- AWS (Official)
- Source
- aws/agent-toolkit-for-aws · skills/specialized-skills/serverless-skills/creating-api-gateway-stage · commit 0a218f8
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- NOTICE (added by AutoGineer from NOTICE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by AWS or AWS.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download creating-api-gateway-stage.zip