-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (37 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const {STS} = require('aws-sdk');
const core = require('@actions/core');
const assumeRole = async () => {
try {
const accessKeyId = core.getInput('access-key-id');
const secretAccessKey = core.getInput('secret-access-key');
const roleArn = core.getInput('role-arn');
const externalId = core.getInput('external-id')
const durationSeconds = core.getInput('duration-seconds');
const sessionName = core.getInput('session-name');
const sts = new STS({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
});
const res = await sts.assumeRole({
RoleArn: roleArn,
ExternalId: externalId,
DurationSeconds: durationSeconds,
RoleSessionName: sessionName,
}).promise()
const credentials = res.Credentials
core.exportVariable('AWS_ACCESS_KEY_ID', credentials.AccessKeyId);
core.exportVariable('AWS_SECRET_ACCESS_KEY', credentials.SecretAccessKey);
core.exportVariable('AWS_SESSION_TOKEN', credentials.SessionToken);
} catch (error) {
core.error(error);
throw new Error(error);
}
}
const main = async () => {
try {
await assumeRole();
} catch (error) {
core.setFailed(error.message);
}
};
main();