Deploy Python Apps to AWS Lambda via GitHub Actions — No Access Keys Required
Deploy Python apps to AWS Lambda from GitHub Actions using OIDC federation. No long-lived credentials needed.
Problem: Long-Lived Credentials in CI/CD
Deploying to AWS from GitHub Actions traditionally means storing AWS access keys and secret keys as GitHub repository secrets. This approach works, but carries real risks:
- Credential sprawl: Keys live in repository secrets, CI logs (if accidentally exposed), and developer machines.
- Rotation burden: Manually cycling credentials across all workflows is tedious and often skipped, leaving stale keys in circulation.
- Blast radius: A leaked key grants full AWS access until discovered and rotated — sometimes days or weeks later.
- Audit trail gaps: It's hard to track who accessed credentials or when.
There's a better way: GitHub's OIDC (OpenID Connect) federation lets your GitHub Actions workflows assume an AWS IAM role without ever storing AWS credentials. GitHub's OIDC provider issues a short-lived token (valid for ~1 hour), AWS IAM validates it, and your workflow gets temporary credentials that auto-expire. No keys, no rotation tax, no stored secrets.
TL;DR
By the end of this guide, you'll have:
- ✅ Registered GitHub as a trusted OIDC identity provider in AWS IAM
- ✅ Created an IAM role that GitHub Actions can assume
- ✅ Configured a GitHub Actions workflow to deploy your FastAPI app to AWS Lambda using only temporary, auto-expiring credentials
- ✅ Verified the deployment end-to-end (no long-lived secrets anywhere)
Full source code for this example: https://github.com/jai-saravanan/github-oidc-aws
This guide walks through a complete, working example: a Python FastAPI application with two endpoints (add customer, retrieve customer) and Swagger documentation, deployed to AWS Lambda from GitHub Actions using keyless OIDC federation. Everything is interleaved — AWS setup first, then the GitHub Actions workflow, then end-to-end verification.
The Sample Application
You're starting with a FastAPI service:
- POST /add-customer: Add a new customer
- GET /get-customers: Retrieve the customer list
- Swagger UI at
/docsfor interactive testing
Running locally, it looks like this:

This is a stateless, HTTP-request-driven application — a natural fit for AWS Lambda. We'll deploy it using the Serverless Framework, which packages the app and sets up the API Gateway integration automatically.
Step 1: Register GitHub as an OIDC Identity Provider in AWS IAM
Before GitHub can hand off tokens to AWS, you need to register GitHub as a trusted identity provider. Open the AWS IAM Console and navigate to Identity Providers:

Click Add Provider, select OpenID Connect, and fill in:
- Provider URL:
https://token.actions.githubusercontent.com - Audience:
sts.amazonaws.com
The audience is the key detail — it tells AWS to only trust tokens issued for the AWS Security Token Service (STS). This is your first layer of security: the token can't be misused for anything else.

Hit Add Provider. AWS fetches GitHub's public signing keys and will cryptographically validate every future token. The provider now shows up in your list:

Step 2: Create an IAM Role That Trusts GitHub
Now you need the destination — an IAM role that GitHub will assume. Navigate to Roles and click Create Role:

Select Web identity as the trusted entity type, then set up the trust relationship:
- Identity Provider: the GitHub OIDC provider you just registered
- Audience:
sts.amazonaws.com - GitHub organization: your org or username (e.g.
jai-saravanan)

The organization/repository/branch fields are what build the sub condition in the trust policy. Leaving repository and branch as * (as shown above) is fine for a demo, but for production scope the subject down to the exact repo:
- Format:
repo:ORG_NAME/REPO_NAME:* - Example:
repo:jai-saravanan/github-oidc-aws:*
Without that scoping, any repository under your organization can assume the role — a gap worth closing before you go live.
Click Next.
Step 3: Grant Deployment Permissions
Now add permissions. Click Create Inline Policy and switch to the JSON tab:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudformation:*",
"lambda:*",
"apigateway:*",
"iam:*",
"logs:*",
"s3:*"
],
"Resource": "*"
}
]
}
This policy is intentionally broad for this demo — note that IAM's own policy checker flags it with a security warning. In production, narrow this down immediately: scope it to specific function name patterns, deployment buckets, and CloudFormation stacks. Start with the minimum permissions and expand only as needed.
Click Next.
Step 4: Name and Create the Role
On the final page, give your role a name — something like oidc or GitHubOIDCDeployRole. This page also shows the generated trust policy, where you can confirm the aud and sub conditions are what you expect:

Add a description like "Role for GitHub Actions to deploy to Lambda via OIDC" for future you, then Create Role. The role now appears in your Roles list, trusted by the GitHub identity provider:

Open the role and copy its ARN from the summary:
arn:aws:iam::123456789012:role/oidc
Copy this ARN — you'll paste it into your GitHub Actions workflow next.
Step 5: Configure Your GitHub Actions Workflow
Time to write the automation. Create .github/workflows/deploy.yml in your repository:

The Serverless Framework is an npm package, not a pip package. pip install serverless will not give you the serverless CLI — you need Node on the runner.
The two essential pieces:
1. id-token: write permission — By default, workflows can't generate OIDC tokens. This permission enables it. Without it, AWS won't trust the token.
2. The configure-aws-credentials step — This is where the handshake happens:
- GitHub generates a signed JWT token
- The action sends it to AWS STS
- AWS validates the signature using GitHub's public keys
- If valid, STS issues temporary credentials (valid ~1 hour)
- These get injected into the workflow environment
- All subsequent steps use them — no secrets stored anywhere
Step 6: Deploy and Verify
Push your workflow file to main or trigger it manually from the Actions tab:

Watch the "Configure AWS credentials via OIDC" step complete successfully — this is where the magic happens. The log shows Assuming role with OIDC followed by Authenticated as assumedRoleId ...:GitHubActions, and the temporary credentials that expire in an hour:

The Serverless Framework then packages your FastAPI app, creates the Lambda function, uploads it, and wires up API Gateway. Find your API Gateway URL in the function's Triggers tab:

Open https://<YOUR_API_GATEWAY_URL>/docs to see the same Swagger UI you ran locally — now served from Lambda:

Click through the endpoints — POST /add-customer to add one, GET /get-customers to retrieve the list. Your app is live, deployed with temporary, auto-expiring credentials. No AWS keys in GitHub Secrets. No credential rotation tax. No security debt.
What You've Accomplished
✅ Registered GitHub as a trusted OIDC provider in AWS IAM — no long-lived keys needed
✅ Created an IAM role with appropriate permissions for Lambda/API Gateway/S3/CloudFormation deployments
✅ Configured a GitHub Actions workflow that assumes the role using a short-lived OIDC token
✅ Deployed a FastAPI application to AWS Lambda from GitHub Actions without storing any AWS credentials
✅ Verified end-to-end — the app runs on Lambda and is accessible via its API Gateway URL
What Changed
- ❌ No AWS access keys in GitHub Secrets
- ❌ No long-lived credentials to rotate or leak
- ✅ Temporary credentials auto-expire in 1 hour
- ✅ Every deployment is cryptographically authenticated
- ✅ Clear audit trail in GitHub Actions logs
You've just built a deployment pipeline that's secure by design — not by process or manual discipline. The infrastructure enforces keylessness; the credentials don't exist long enough to be stolen. That's the win.
From here, consider narrowing your IAM policy to specific Lambda function patterns, S3 buckets, and CloudFormation stacks rather than *. Add tests and security scans before the deploy step. Set up CloudWatch alarms to catch runtime issues.
For the full source code and examples, visit https://github.com/jai-saravanan/github-oidc-aws.