This project demonstrates how to set up secure authentication to AWS APIs using *IAM Policies, **AWS CLI, **AWS Lambda, and *API Gateway.
The goal is to implement robust authentication mechanisms that restrict access to AWS resources through APIs, ensuring only authorized requests can invoke protected services.
- Create a dedicated IAM User for API authentication.
- Install & configure the AWS CLI for secure access.
- Deploy a Lambda Function as the backend for API Gateway.
- Create and configure an API Gateway resource (/login) with a POST method.
- Enable secure permissions for API Gateway to invoke Lambda.
- Deploy and test the API securely from the terminal using curl.
- An AWS Account
- Installed AWS CLI v2
- Basic knowledge of AWS services: IAM, Lambda, API Gateway
- Created an IAM role to encapsulate permissions required for managing EC2 and S3 resources.
- This role provides the trust relationship and access model for automation.
Policy granting full access to EC2 and S3:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:*",
"s3:*"
],
"Resource": "*"
}
]
}- Created a user named automation_user.
- This will serve as the primary entity used by scripts to interact with AWS APIs.
- Linked automation_user to the created IAM role.
- Ensures the user inherits necessary permissions.
- Attached the EC2 + S3 full access policy to automation_user.
- Ensures explicit permission enforcement.
- Generated Access Key ID and Secret Access Key for automation_user.
- These are required for authentication via AWS CLI and scripts.
- Configured AWS CLI with the generated credentials:
- aws configure
- aws sts get-caller-identity
With secure authentication configured, the next step is to deploy a Lambda-backed API.
Python Lambda handler:
def lambda_handler(event, context): return { 'statusCode': 200, 'body': "Hello from Zappy Lambda!" }
- Created /login resource under the root.
- Configured POST method.
- Integrated method with Lambda using AWS_PROXY.
aws lambda add-permission
--function-name zappyLambda
--statement-id apigateway-test-1
--action lambda:InvokeFunction
--principal apigateway.amazonaws.com
--source-arn arn:aws:execute-api:us-east-1:<ACCOUNT_ID>:<API_ID>/*/POST/login
aws apigateway create-deployment
--rest-api-id <API_ID>
--stage-name dev
--region us-east-1
curl -X POST https://<API_ID>.execute-api.us-east-1.amazonaws.com/dev/login
✅ Response:
Hello from Zappy Lambda!
Unauthorized requests return:
{"message": "Missing Authentication Token"}
Authorized POST /login requests return:
Hello from Zappy Lambda!
In this project, we successfully:
-
Created IAM roles, policies, and users for secure access.
-
Configured AWS CLI for programmatic authentication.
-
Designed and deployed a Lambda function with API Gateway.
-
Ensured only authenticated API requests succeed.
This validates that IAM policies and API Gateway authentication provide robust mechanisms to prevent unauthorized access while enabling controlled API interaction.

























