Skip to content

Commit

Permalink
fix: only use custom task role name on Fargate when provided (#3469)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryasaatvik authored Feb 6, 2025
1 parent 12443cf commit b9f8a44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 4 additions & 2 deletions packages/artillery/lib/cmds/run-fargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ class RunCommand extends Command {
}
}

flags.taskRoleName = flags['task-role-name'] || ECS_WORKER_ROLE_NAME;

const ECS = new PlatformECS(
null,
null,
{},
{ testRunId: 'foo', region: flags.region }
{ testRunId: 'foo', region: flags.region, taskRoleName: flags.taskRoleName }
);
await ECS.init();
flags.taskRoleName = flags['task-role-name'] || ECS_WORKER_ROLE_NAME;

process.env.USE_NOOP_BACKEND_STORE = 'true';

telemetry.capture('run:fargate', {
Expand Down
20 changes: 8 additions & 12 deletions packages/artillery/lib/platform/aws-ecs/ecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const AWS = require('aws-sdk');

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

const {
S3_BUCKET_NAME_PREFIX,
ECS_WORKER_ROLE_NAME
} = require('../aws/constants');
const { S3_BUCKET_NAME_PREFIX } = require('../aws/constants');

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

Expand Down Expand Up @@ -48,12 +45,11 @@ class PlatformECS {

async init() {
await setDefaultAWSCredentials(AWS);

this.accountId = await getAccountId();

await ensureSSMParametersExist(this.platformOpts.region);
await ensureS3BucketExists('global', this.s3LifecycleConfigurationRules);
await createIAMResources(this.accountId);
await createIAMResources(this.accountId, this.platformOpts.taskRoleName);
}

async createWorker() {}
Expand Down Expand Up @@ -112,19 +108,19 @@ async function ensureSSMParametersExist(region) {
);
}

async function createIAMResources(accountId) {
const workerRoleArn = await createWorkerRole(accountId);
async function createIAMResources(accountId, taskRoleName) {
const workerRoleArn = await createWorkerRole(accountId, taskRoleName);

return {
workerRoleArn
};
}

async function createWorkerRole(accountId) {
async function createWorkerRole(accountId, taskRoleName) {
const iam = new AWS.IAM();

try {
const res = await iam.getRole({ RoleName: ECS_WORKER_ROLE_NAME }).promise();
const res = await iam.getRole({ RoleName: taskRoleName }).promise();
return res.Role.Arn;
} catch (err) {
debug(err);
Expand All @@ -145,7 +141,7 @@ async function createWorkerRole(accountId) {
]
}),
Path: '/',
RoleName: ECS_WORKER_ROLE_NAME
RoleName: taskRoleName
})
.promise();

Expand Down Expand Up @@ -231,7 +227,7 @@ async function createWorkerRole(accountId) {
await iam
.attachRolePolicy({
PolicyArn: createPolicyResp.Policy.Arn,
RoleName: ECS_WORKER_ROLE_NAME
RoleName: taskRoleName
})
.promise();

Expand Down

0 comments on commit b9f8a44

Please sign in to comment.