{"id":1471,"date":"2020-03-21T08:25:31","date_gmt":"2020-03-21T13:25:31","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=1471"},"modified":"2020-04-12T11:49:12","modified_gmt":"2020-04-12T16:49:12","slug":"using-aws-cli-docker-image","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/using-aws-cli-docker-image\/","title":{"rendered":"Using AWS CLI Docker image"},"content":{"rendered":"

Recording my test running AWS CLI in a docker image.<\/h3>\n
## get a base ubuntu image\n\n# docker pull ubuntu\nUsing default tag: latest\nlatest: Pulling from library\/ubuntu\n...\n\n## install the Aws CLI and commit to a image\n\n# docker run -it --name awscli ubuntu \/bin\/bash\nroot@25b777958aad:\/# apt update\nroot@25b777958aad:\/# apt upgrade\nroot@25b777958aad:\/# apt install awscli\nroot@25b777958aad:\/# exit\n\n# docker commit 25b777958aad awscli\nsha256:9e1f0fef4051c86c3e1b9beecd20b29a3f11f86b5a63f1d03fefc41111f8fb47\n\n## alias to run a docker image with cli commands\n\n# alias awscli=docker run -it --name aws-iqonda --rm -e AWS_DEFAULT_REGION='us-east-1' -e AWS_ACCESS_KEY_ID='<...>' -e AWS_SECRET_ACCESS_KEY='<...>' --entrypoint aws awscli\n\n# awscli s3 ls | grep ls-al\n2016-02-17 15:43:57 j.ls-al.com\n\n# awscli ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text\ni-0e38cd17dfed16658 ec2server   running 172.31.48.7 xxx.xxx.xxx.xxx\n\n## one way to hide key variables with pass\/gpg https:\/\/blog.gruntwork.io\/authenticating-to-aws-with-environment-variables-e793d6f6d02e\n\n$ pass init <email@addr.ess>\n$ pass insert awscreds-iqonda\/aws-access-key-id\n$ pass insert awscreds-iqonda\/aws-secret-access-key\n\n$ pass\nPassword Store\n\u2514\u2500\u2500 awscreds-iqonda\n    \u251c\u2500\u2500 aws-access-key-id\n    \u2514\u2500\u2500 aws-secret-access-key\n\n$ pass awscreds-iqonda\/aws-access-key-id\n<...>\n$ pass awscreds-iqonda\/aws-secret-access-key\n<...>\n\n$ export AWS_ACCESS_KEY_ID=$(pass awscreds-iqonda\/aws-access-key-id)\n$ export AWS_SECRET_ACCESS_KEY=$(pass awscreds-iqonda\/aws-secret-access-key)\n\n** TODO: how to batch this? this is fine for desktop use but I do not want a gpg keyring password prompt either text or graphic in a server scripting situation. Maybe look at hashicorp vault?\n\n$ env | grep AWS\nAWS_SECRET_ACCESS_KEY=<...>\nAWS_ACCESS_KEY_ID=<...>\n\n## for convenience use an alias\n$ alias awscli=sudo docker run -it --name aws-iqonda --rm -e AWS_DEFAULT_REGION='us-east-1' -e AWS_ACCESS_KEY_ID='$AWS_ACCESS_KEY_ID' -e AWS_SECRET_ACCESS_KEY='$AWS_SECRET_ACCESS_KEY' --entrypoint aws awscli\n\n$ awscli s3 ls <\/code><\/pre>\n

Some useful References:<\/h3>\n