Ansible¶
# aws_cli.yaml
--- # ansible-playbook aws_cli.yaml --ask-become-pass
- name: Install AWS CLI v2 locally
hosts: localhost
connection: local
become: true
vars:
owner_user: [ your_username ]
owner_dir: /home/[ your_username ]/.local
tasks:
- name: Ensure unzip is installed
package:
name: unzip
state: present
- name: Download AWS CLI v2 bundle
get_url:
url: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
dest: /tmp/awscliv2.zip
mode: '0644'
owner: "{{ owner_user }}"
group: "{{ owner_user }}"
- name: Unzip AWS CLI v2 bundle
unarchive:
src: /tmp/awscliv2.zip
dest: /tmp/
remote_src: true
owner: "{{ owner_user }}"
group: "{{ owner_user }}"
creates: /tmp/aws
- name: Install or update AWS CLI v2
command: ./aws/install --bin-dir "{{ owner_dir }}/bin" --install-dir "{{ owner_dir }}/aws-cli" --update
args:
chdir: /tmp
register: aws_install
changed_when: "'Already installed' not in aws_install.stdout"
- name: Ensure installation directories are owned by specific user
file:
path: "{{ owner_dir }}/aws-cli"
owner: "{{ owner_user }}"
group: "{{ owner_user }}"
recurse: true
- name: Verify AWS CLI installation
command: aws --version
register: aws_version
changed_when: false
- debug:
msg: "AWS CLI installed: {{ aws_version.stdout }}"
ansible-playbook aws_cli.yaml --ask-become-pass
type aws
aws is /home/[ your_username ]/.local/bin/aws
Container¶
Ephemeral container¶
Create a volume¶
podman create volume az-config
Pull the container image¶
podman pull public.ecr.aws/aws-cli/aws-cli:latest
Set an alias¶
alias aws='podman run --rm -it -v awscli-config:/root/.aws:Z docker.io/amazon/aws-cli:latest'
type aws
aws is aliased to `podman run --rm -it -v awscli-config:/root/.aws:Z public.ecr.aws/aws-cli/aws-cli:latest'
Make the alias permanent:
echo "alias aws='podman run --rm -it -v awscli-config:/root/.aws:Z docker.io/amazon/aws-cli:latest'" >> ~/.bashrc.d/cloud_aliases.sh
Initialize a configuration¶
aws configure
Compose file¶
# compose.yaml
services:
awscli:
image: public.ecr.aws/aws-cli/aws-cli:latest
container_name: awscli
volumes:
- awscli-config:/root/.aws:Z
stdin_open: true
tty: true
command: ["/bin/bash"]
volumes:
awscli-config:
name: awscli-config
driver: local
podman-compose run --rm aws
podman-compose run --rm aws configure
Pip package¶
pip install awscli --user