Skip to content

Commit

Permalink
refactor: remove hardcoded ECS worker role name constant
Browse files Browse the repository at this point in the history
Update IAM resource creation to pass task role name as a parameter, removing the hardcoded constant and improving flexibility in role management.
  • Loading branch information
aryasaatvik committed Feb 5, 2025
1 parent 5b9d613 commit 3085672
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 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 @@ -52,7 +49,7 @@ class PlatformECS {

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 @@ -111,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: this.platformOpts.taskRoleName }).promise();
const res = await iam.getRole({ RoleName: taskRoleName }).promise();
return res.Role.Arn;
} catch (err) {
debug(err);
Expand All @@ -144,7 +141,7 @@ async function createWorkerRole(accountId) {
]
}),
Path: '/',
RoleName: ECS_WORKER_ROLE_NAME
RoleName: taskRoleName
})
.promise();

Expand Down Expand Up @@ -230,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 3085672

Please sign in to comment.