Skip to content

Commit d479691

Browse files
committed
Create action to authenticate with AWS using the generated role name
1 parent 44e4627 commit d479691

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: AWS Auth
2+
3+
description: |
4+
This is an opinionated action to authenticate with AWS.
5+
It will generate a role ARN based on the repository name and the AWS account ID.
6+
7+
inputs:
8+
aws_account_id:
9+
description: 'The AWS account ID to generate the role ARN for'
10+
required: true
11+
default: '197730964718' # elastic-web
12+
aws_region:
13+
description: 'The AWS region to use'
14+
required: false
15+
default: 'us-east-1'
16+
aws_role_name_prefix:
17+
description: 'The prefix for the role name'
18+
required: false
19+
default: 'elastic-docs-v3-preview-'
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Generate AWS Role ARN
25+
id: role_arn
26+
shell: python
27+
env:
28+
AWS_ACCOUNT_ID: ${{ inputs.aws_account_id }}
29+
ROLE_NAME_PREFIX: ${{ inputs.aws_role_name_prefix }}
30+
run: |
31+
import hashlib
32+
import os
33+
prefix = os.environ["ROLE_NAME_PREFIX"]
34+
m = hashlib.sha256()
35+
m.update(os.environ["GITHUB_REPOSITORY"].encode('utf-8'))
36+
hash = m.hexdigest()[:64-len(prefix)]
37+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
38+
f.write(f"result=arn:aws:iam::{os.environ["AWS_ACCOUNT_ID"]}:role/{prefix}{hash}")
39+
- name: Configure AWS Credentials
40+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
41+
with:
42+
role-to-assume: ${{ steps.role_arn.outputs.result }}
43+
aws-region: ${{ inputs.aws_region }}

0 commit comments

Comments
 (0)