#!/bin/bash # Assume the role using locally configured AWS credentials, then pass the assumed role to the container via environment # variables! ASSUMED_ROLE=$(aws sts assume-role \ --role-arn "arn:aws:iam::000000000000:role/our-role-to-assume" \ --role-session-name "session_name" \ --output text) # 'docker-compose exec' seems to set the shell width incorrectly, here we overcome that by manually setting COLUMNS and # LINES! docker-compose exec \ -e COLUMNS=$(tput cols) \ -e LINES=$(tput lines) \ -e AWS_ACCESS_KEY_ID=$(echo $ASSUMED_ROLE | awk '{print $5}') \ -e AWS_SECRET_ACCESS_KEY=$(echo $ASSUMED_ROLE | awk '{print $7}') \ -e AWS_SESSION_TOKEN=$(echo $ASSUMED_ROLE | awk '{print $8}') \ container_name bash