AWS API Gateway User anonymous is not authorized to execute API
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Amazon Web Services (AWS) API Gateway is a powerful service that allows developers to create, maintain, and secure APIs at any scale. However, users can occasionally encounter permission-related issues, such as the error message: "User anonymous is not authorized to execute API." This article explores the components, configurations, and troubleshooting steps related to this authorization error.
Understanding the Components
API Gateway
AWS API Gateway acts as a front door for applications to access data, business logic, or functionality from backend services like AWS Lambda functions, EC2 instances, or HTTP APIs.
IAM Roles and Policies
Permissions in AWS are managed using Identity and Access Management (IAM). When you configure permissions, you must create policies that explicitly allow users to call your API methods.
Authorization Mechanisms
- IAM Permissions: Used to manage access to AWS resources.
- Lambda Authorizers: Custom AWS Lambda functions to control access to APIs.
- Cognito User Pools: Provides federated identities by leveraging social logins or SAML.
- API Keys: A straightforward way to control access with little overhead.
Common Causes of Authorization Errors
Missing IAM Policy
The most common cause of "User anonymous is not authorized to execute API" is a missing or incorrectly configured IAM policy. Ensure the policy attached to the user or role includes permissions for `execute-api:Invoke`.
Incorrect Resource Path
Check if the `Resource` field in your IAM policy is explicitly allowing the method and resource path.
CORS Issues
Cross-Origin Resource Sharing (CORS) can lead to invocation issues if not correctly configured, especially for APIs accessed from web browsers.
Troubleshooting Steps
To resolve the "User anonymous is not authorized to execute API" error, follow these steps:
- Verify API Method Settings:
- Check if the method has "AWS_IAM" as its authorization type if you are using IAM authorizations.
- Check Associated IAM Policies:
- Ensure the IAM user or role making the request has correct permissions.
- Policy example:
- Use the IAM Policy Simulator to validate the permissions granted to your IAM user or role.
- Enable logging for better visibility. Use CloudWatch Logs to see detailed request information.
- Ensure the API Gateway method is configured correctly for CORS if accessed from a browser.
- Use tools like Postman or `cURL` to test API calls with credentials to isolate issues.
- If using a Lambda Authorizer, make sure it returns a correct IAM policy denying or allowing access.
Related reading
- AWS API Gateway VPC Link Pricing
- AWS API Get Any Resource By ARN
- AWS AppSync Event Subscription Filtering on Cognito User
- AWS AssumeRole - User is not authorized to perform stsAssumeRole on resource
- AWS Athena too slow for an api?
- AWS CDK how to create an API Gateway backed by Lambda from OpenApi spec?
- AWS Certificate Manager Requested a certificate reporting 'Renewal eligibility Ineligible?
- AWS CLI Key is not in valid OpenSSH public key format

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.