Skip to content

Commit b9f8a44

Browse files
authored
fix: only use custom task role name on Fargate when provided (#3469)
1 parent 12443cf commit b9f8a44

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

packages/artillery/lib/cmds/run-fargate.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ class RunCommand extends Command {
7575
}
7676
}
7777

78+
flags.taskRoleName = flags['task-role-name'] || ECS_WORKER_ROLE_NAME;
79+
7880
const ECS = new PlatformECS(
7981
null,
8082
null,
8183
{},
82-
{ testRunId: 'foo', region: flags.region }
84+
{ testRunId: 'foo', region: flags.region, taskRoleName: flags.taskRoleName }
8385
);
8486
await ECS.init();
85-
flags.taskRoleName = flags['task-role-name'] || ECS_WORKER_ROLE_NAME;
87+
8688
process.env.USE_NOOP_BACKEND_STORE = 'true';
8789

8890
telemetry.capture('run:fargate', {

packages/artillery/lib/platform/aws-ecs/ecs.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ const AWS = require('aws-sdk');
1111

1212
const { ensureParameterExists } = require('./legacy/aws-util');
1313

14-
const {
15-
S3_BUCKET_NAME_PREFIX,
16-
ECS_WORKER_ROLE_NAME
17-
} = require('../aws/constants');
14+
const { S3_BUCKET_NAME_PREFIX } = require('../aws/constants');
1815

1916
const getAccountId = require('../aws/aws-get-account-id');
2017

@@ -48,12 +45,11 @@ class PlatformECS {
4845

4946
async init() {
5047
await setDefaultAWSCredentials(AWS);
51-
5248
this.accountId = await getAccountId();
5349

5450
await ensureSSMParametersExist(this.platformOpts.region);
5551
await ensureS3BucketExists('global', this.s3LifecycleConfigurationRules);
56-
await createIAMResources(this.accountId);
52+
await createIAMResources(this.accountId, this.platformOpts.taskRoleName);
5753
}
5854

5955
async createWorker() {}
@@ -112,19 +108,19 @@ async function ensureSSMParametersExist(region) {
112108
);
113109
}
114110

115-
async function createIAMResources(accountId) {
116-
const workerRoleArn = await createWorkerRole(accountId);
111+
async function createIAMResources(accountId, taskRoleName) {
112+
const workerRoleArn = await createWorkerRole(accountId, taskRoleName);
117113

118114
return {
119115
workerRoleArn
120116
};
121117
}
122118

123-
async function createWorkerRole(accountId) {
119+
async function createWorkerRole(accountId, taskRoleName) {
124120
const iam = new AWS.IAM();
125121

126122
try {
127-
const res = await iam.getRole({ RoleName: ECS_WORKER_ROLE_NAME }).promise();
123+
const res = await iam.getRole({ RoleName: taskRoleName }).promise();
128124
return res.Role.Arn;
129125
} catch (err) {
130126
debug(err);
@@ -145,7 +141,7 @@ async function createWorkerRole(accountId) {
145141
]
146142
}),
147143
Path: '/',
148-
RoleName: ECS_WORKER_ROLE_NAME
144+
RoleName: taskRoleName
149145
})
150146
.promise();
151147

@@ -231,7 +227,7 @@ async function createWorkerRole(accountId) {
231227
await iam
232228
.attachRolePolicy({
233229
PolicyArn: createPolicyResp.Policy.Arn,
234-
RoleName: ECS_WORKER_ROLE_NAME
230+
RoleName: taskRoleName
235231
})
236232
.promise();
237233

0 commit comments

Comments
 (0)