This project demonstrates how to use Ansible with AWS credentials (including AWS SSO) to fetch and list AWS Lambda functions.
. ├── ansible.cfg ├── lambda_list.yml ├── inventory.ini (optional) └── venv/
- Python 3.8+
- AWS CLI v2 with SSO configured
- Active AWS SSO session
- Ansible (installed in a virtualenv)
boto3,botocore,amazon.awscollection
python3 -m venv venv
source venv/bin/activate
pip install ansible boto3 botocore
ansible-galaxy collection install amazon.aws
[defaults]
interpreter_python = ./venv/bin/python
deprecation_warnings = False
aws configure sso --profile 88HoursDevOps
aws sso login --profile 88HoursDevOps
- name: List Lambda functions
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Fetch Lambda list
amazon.aws.lambda_info:
region: ap-south-1
profile: 88HoursDevOps
register: lambda_info
- name: Show function names
debug:
msg: "{{ item.function_name }}"
loop: "{{ lambda_info.functions }}"
ansible-playbook lambda_list.yml
- ✅
region: ap-south-1→ don’t use invalid regions likeap-south-2 - ✅
register:must be at task level, not inside the module - ✅
profile:is required when using AWS SSO (env vars won't work) - ✅ Ensure
boto3andansibleare installed in the same venv - ✅ Use Ansible binary from the venv:
which ansibleshould point to./venv/bin/ansible - ✅ Use
interpreter_pythoninansible.cfgto bind it to your venv
To test your profile works:
python3 -c 'import boto3; print(boto3.Session(profile_name="88HoursDevOps").client("sts").get_caller_identity())'
- Filter Lambda by name or tag
- Use dynamic inventory for AWS EC2
- Extend playbook to deploy or update functions