Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve support for arbitrary s3 endpoints and for multiple aws profiles #240

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion guidebooks/aws/_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ validate: |
To learn more, and to get your credentials from the AWS console, [look
here](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html).

=== "AWS Endpoint [default: https://s3.amazonaws.com]"
```shell
export S3_ENDPOINT=${choice}
```

=== "AWS Access Key Id [default: none]"
```shell
export S3_ACCESS_KEY_ID=${choice}
```

=== "AWS Secret Access Key [default: none]"
```shell
export S3_SECRET_ACCESS_KEY=${choice}
Expand Down
15 changes: 12 additions & 3 deletions guidebooks/aws/auth.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
imports:
- aws/choose/profile
---

# AWS Credentials

You may also manually store your AWS credentials in ~/.aws/credentials. The file will look something like
Expand All @@ -9,19 +14,23 @@ aws_secret_access_key = yyy
```

```shell
export S3_ENDPOINT=https://s3.amazonaws.com
export S3_ENDPOINT_FROM_CONFIG=$(cat ~/.aws/config | awk -v AWS_PROFILE=${AWS_PROFILE-default} '$1 == "[" AWS_PROFILE "]" {on=1} $1 ~ "]" && $1 != "[" AWS_PROFILE "]" {on=0} on==1 && $0 ~ "endpoint_url" {sub(/endpoint_url *= */,""); print $0}')
```

```shell
export S3_ENDPOINT=${S3_ENDPOINT_FROM_CONFIG-https://s3.amazonaws.com}
```

```shell
export S3_ACCESS_KEY_ID=$(grep aws_access_key_id ~/.aws/credentials | awk -F ' = ' '{ print $2 }')
export S3_ACCESS_KEY_ID=$(cat ~/.aws/credentials | awk -v AWS_PROFILE=${AWS_PROFILE-default} '$1 == "[" AWS_PROFILE "]" {on=1} $1 ~ "]" && $1 != "[" AWS_PROFILE "]" {on=0} on==1 && $0 ~ "aws_access_key_id" {sub(/aws_access_key_id *= */,""); print $0}')
```

```shell
export AWS_ACCESS_KEY_ID=${S3_ACCESS_KEY_ID}
```

```shell
export S3_SECRET_ACCESS_KEY=$(grep aws_secret_access_key ~/.aws/credentials | awk -F ' = ' '{ print $2 }')
export S3_SECRET_ACCESS_KEY=$(cat ~/.aws/credentials | awk -v AWS_PROFILE=${AWS_PROFILE-default} '$1 == "[" AWS_PROFILE "]" {on=1} $1 ~ "]" && $1 != "[" AWS_PROFILE "]" {on=0} on==1 && $0 ~ "aws_secret_access_key" {sub(/aws_secret_access_key *= */,""); print $0}')
```

```shell
Expand Down
11 changes: 11 additions & 0 deletions guidebooks/aws/choose/profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Choose an AWS Profile

```shell
if [ ! -d ~/.aws ]; then mkdir ~/.aws; fi
if [ ! -f ~/.aws/config ]; then echo "[default]" > ~/.aws/config; fi
```

=== "expand(cat ~/.aws/config | grep -E '^\\[' | tr -d '[]')"
```shell
export AWS_PROFILE="${choice}"
```