@depup/artillery 2.0.30-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +63 -0
  2. package/bin/run +29 -0
  3. package/bin/run.cmd +3 -0
  4. package/changes.json +138 -0
  5. package/console-reporter.js +1 -0
  6. package/lib/artillery-global.js +33 -0
  7. package/lib/cli/banner.js +8 -0
  8. package/lib/cli/common-flags.js +80 -0
  9. package/lib/cli/hooks/version.js +20 -0
  10. package/lib/cmds/dino.js +109 -0
  11. package/lib/cmds/quick.js +122 -0
  12. package/lib/cmds/report.js +34 -0
  13. package/lib/cmds/run-aci.js +91 -0
  14. package/lib/cmds/run-fargate.js +192 -0
  15. package/lib/cmds/run-lambda.js +96 -0
  16. package/lib/cmds/run.js +671 -0
  17. package/lib/console-capture.js +92 -0
  18. package/lib/console-reporter.js +438 -0
  19. package/lib/create-bom/built-in-plugins.js +12 -0
  20. package/lib/create-bom/create-bom.js +301 -0
  21. package/lib/dispatcher.js +9 -0
  22. package/lib/dist.js +222 -0
  23. package/lib/index.js +5 -0
  24. package/lib/launch-platform.js +439 -0
  25. package/lib/load-plugins.js +113 -0
  26. package/lib/platform/aws/aws-cloudwatch.js +106 -0
  27. package/lib/platform/aws/aws-create-sqs-queue.js +58 -0
  28. package/lib/platform/aws/aws-ensure-s3-bucket-exists.js +78 -0
  29. package/lib/platform/aws/aws-get-account-id.js +26 -0
  30. package/lib/platform/aws/aws-get-bucket-region.js +18 -0
  31. package/lib/platform/aws/aws-get-credentials.js +28 -0
  32. package/lib/platform/aws/aws-get-default-region.js +26 -0
  33. package/lib/platform/aws/aws-whoami.js +15 -0
  34. package/lib/platform/aws/constants.js +7 -0
  35. package/lib/platform/aws/iam-cf-templates/aws-iam-fargate-cf-template.yml +219 -0
  36. package/lib/platform/aws/iam-cf-templates/aws-iam-lambda-cf-template.yml +125 -0
  37. package/lib/platform/aws/iam-cf-templates/gh-oidc-fargate.yml +241 -0
  38. package/lib/platform/aws/iam-cf-templates/gh-oidc-lambda.yml +153 -0
  39. package/lib/platform/aws-ecs/ecs.js +247 -0
  40. package/lib/platform/aws-ecs/legacy/aws-util.js +134 -0
  41. package/lib/platform/aws-ecs/legacy/bom.js +528 -0
  42. package/lib/platform/aws-ecs/legacy/constants.js +27 -0
  43. package/lib/platform/aws-ecs/legacy/create-s3-client.js +24 -0
  44. package/lib/platform/aws-ecs/legacy/create-test.js +247 -0
  45. package/lib/platform/aws-ecs/legacy/errors.js +34 -0
  46. package/lib/platform/aws-ecs/legacy/find-public-subnets.js +149 -0
  47. package/lib/platform/aws-ecs/legacy/plugins/artillery-plugin-inspect-script/index.js +27 -0
  48. package/lib/platform/aws-ecs/legacy/plugins/artillery-plugin-sqs-reporter/azure-aqs.js +80 -0
  49. package/lib/platform/aws-ecs/legacy/plugins/artillery-plugin-sqs-reporter/index.js +202 -0
  50. package/lib/platform/aws-ecs/legacy/plugins.js +16 -0
  51. package/lib/platform/aws-ecs/legacy/run-cluster.js +1994 -0
  52. package/lib/platform/aws-ecs/legacy/sqs-reporter.js +401 -0
  53. package/lib/platform/aws-ecs/legacy/tags.js +22 -0
  54. package/lib/platform/aws-ecs/legacy/test-run-status.js +9 -0
  55. package/lib/platform/aws-ecs/legacy/time.js +67 -0
  56. package/lib/platform/aws-ecs/legacy/util.js +97 -0
  57. package/lib/platform/aws-ecs/worker/Dockerfile +64 -0
  58. package/lib/platform/aws-ecs/worker/helpers.sh +80 -0
  59. package/lib/platform/aws-ecs/worker/loadgen-worker +656 -0
  60. package/lib/platform/aws-lambda/dependencies.js +130 -0
  61. package/lib/platform/aws-lambda/index.js +734 -0
  62. package/lib/platform/aws-lambda/lambda-handler/a9-handler-dependencies.js +73 -0
  63. package/lib/platform/aws-lambda/lambda-handler/a9-handler-helpers.js +43 -0
  64. package/lib/platform/aws-lambda/lambda-handler/a9-handler-index.js +235 -0
  65. package/lib/platform/aws-lambda/lambda-handler/package.json +15 -0
  66. package/lib/platform/aws-lambda/prices.js +29 -0
  67. package/lib/platform/az/aci.js +694 -0
  68. package/lib/platform/az/aqs-queue-consumer.js +88 -0
  69. package/lib/platform/az/regions.js +52 -0
  70. package/lib/platform/cloud/api.js +72 -0
  71. package/lib/platform/cloud/cloud.js +448 -0
  72. package/lib/platform/cloud/http-client.js +19 -0
  73. package/lib/platform/local/artillery-worker-local.js +154 -0
  74. package/lib/platform/local/index.js +174 -0
  75. package/lib/platform/local/worker.js +261 -0
  76. package/lib/platform/worker-states.js +13 -0
  77. package/lib/queue-consumer/index.js +56 -0
  78. package/lib/stash.js +41 -0
  79. package/lib/telemetry.js +78 -0
  80. package/lib/util/await-on-ee.js +24 -0
  81. package/lib/util/generate-id.js +9 -0
  82. package/lib/util/parse-tag-string.js +21 -0
  83. package/lib/util/prepare-test-execution-plan.js +216 -0
  84. package/lib/util/sleep.js +7 -0
  85. package/lib/util/validate-script.js +132 -0
  86. package/lib/util.js +294 -0
  87. package/lib/utils-config.js +31 -0
  88. package/package.json +323 -0
  89. package/types.d.ts +317 -0
  90. package/util.js +1 -0
@@ -0,0 +1,58 @@
1
+ const {
2
+ SQSClient,
3
+ CreateQueueCommand,
4
+ ListQueuesCommand
5
+ } = require('@aws-sdk/client-sqs');
6
+ const debug = require('debug')('artillery:aws-create-sqs-queue');
7
+ const sleep = require('../../util/sleep');
8
+
9
+ // TODO: Add timestamp to SQS queue name for automatic GC
10
+ async function createSQSQueue(region, queueName) {
11
+ const sqs = new SQSClient({
12
+ region
13
+ });
14
+
15
+ const params = {
16
+ QueueName: queueName,
17
+ Attributes: {
18
+ FifoQueue: 'true',
19
+ ContentBasedDeduplication: 'false',
20
+ MessageRetentionPeriod: '1800',
21
+ VisibilityTimeout: '600'
22
+ }
23
+ };
24
+
25
+ const result = await sqs.send(new CreateQueueCommand(params));
26
+ const sqsQueueUrl = result.QueueUrl;
27
+
28
+ // Wait for the queue to be available:
29
+ let waited = 0;
30
+ let ok = false;
31
+ while (waited < 120 * 1000) {
32
+ try {
33
+ const results = await sqs.send(
34
+ new ListQueuesCommand({ QueueNamePrefix: queueName })
35
+ );
36
+ if (results.QueueUrls && results.QueueUrls.length === 1) {
37
+ debug('SQS queue created:', queueName);
38
+ ok = true;
39
+ break;
40
+ } else {
41
+ await sleep(10 * 1000);
42
+ waited += 10 * 1000;
43
+ }
44
+ } catch (_err) {
45
+ await sleep(10 * 1000);
46
+ waited += 10 * 1000;
47
+ }
48
+ }
49
+
50
+ if (!ok) {
51
+ debug('Time out waiting for SQS queue:', queueName);
52
+ throw new Error('SQS queue could not be created');
53
+ }
54
+
55
+ return sqsQueueUrl;
56
+ }
57
+
58
+ module.exports = createSQSQueue;
@@ -0,0 +1,78 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ const debug = require('debug')('util:aws:ensureS3BucketExists');
6
+
7
+ const {
8
+ S3Client,
9
+ PutBucketLifecycleConfigurationCommand,
10
+ CreateBucketCommand,
11
+ NoSuchBucket
12
+ } = require('@aws-sdk/client-s3');
13
+
14
+ const getAWSAccountId = require('./aws-get-account-id');
15
+ const createS3Client = require('../aws-ecs/legacy/create-s3-client');
16
+ const { S3_BUCKET_NAME_PREFIX } = require('./constants');
17
+ const { getBucketRegion } = require('./aws-get-bucket-region');
18
+
19
+ const setBucketLifecyclePolicy = async (
20
+ bucketName,
21
+ lifecycleConfigurationRules,
22
+ region
23
+ ) => {
24
+ const s3 = createS3Client({ region });
25
+ const params = {
26
+ Bucket: bucketName,
27
+ LifecycleConfiguration: {
28
+ Rules: lifecycleConfigurationRules
29
+ }
30
+ };
31
+ try {
32
+ await s3.send(new PutBucketLifecycleConfigurationCommand(params));
33
+ } catch (err) {
34
+ debug('Error setting lifecycle policy');
35
+ debug(err);
36
+ }
37
+ };
38
+
39
+ // Create an S3 bucket in the given region if it doesn't already exist.
40
+ // By default, the bucket will be created without specifying a specific region.
41
+ // Sometimes we need to use region-specific buckets, e.g. when
42
+ // creating Lambda functions from a zip file in S3 the region of the
43
+ // Lambda and the region of the S3 bucket must match.
44
+ module.exports = async function ensureS3BucketExists(
45
+ region,
46
+ lifecycleConfigurationRules = [],
47
+ withRegionSpecificName = false
48
+ ) {
49
+ const accountId = await getAWSAccountId();
50
+ let bucketName = `${S3_BUCKET_NAME_PREFIX}-${accountId}`;
51
+ if (withRegionSpecificName) {
52
+ bucketName = `${S3_BUCKET_NAME_PREFIX}-${accountId}-${region}`;
53
+ }
54
+
55
+ const s3 = new S3Client({ region });
56
+
57
+ let location;
58
+ try {
59
+ location = await getBucketRegion(bucketName);
60
+ } catch (err) {
61
+ if (err instanceof NoSuchBucket) {
62
+ await s3.send(new CreateBucketCommand({ Bucket: bucketName }));
63
+ } else {
64
+ throw err;
65
+ }
66
+ }
67
+
68
+ if (lifecycleConfigurationRules.length > 0) {
69
+ await setBucketLifecyclePolicy(
70
+ bucketName,
71
+ lifecycleConfigurationRules,
72
+ location
73
+ );
74
+ }
75
+
76
+ debug(bucketName);
77
+ return bucketName;
78
+ };
@@ -0,0 +1,26 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ const debug = require('debug')('util:aws:getAccountId');
6
+ const { STSClient, GetCallerIdentityCommand } = require('@aws-sdk/client-sts');
7
+
8
+ module.exports = async function getAccountId(stsOpts = {}) {
9
+ if (!stsOpts.region) {
10
+ stsOpts.region = global.artillery.awsRegion || 'us-east-1';
11
+ }
12
+
13
+ if (process.env.ARTILLERY_STS_OPTS) {
14
+ stsOpts = Object.assign(
15
+ stsOpts,
16
+ JSON.parse(process.env.ARTILLERY_STS_OPTS)
17
+ );
18
+ }
19
+
20
+ const sts = new STSClient(stsOpts);
21
+ const result = await sts.send(new GetCallerIdentityCommand({}));
22
+ const awsAccountId = result.Account;
23
+
24
+ debug(awsAccountId);
25
+ return awsAccountId;
26
+ };
@@ -0,0 +1,18 @@
1
+ const { S3Client, GetBucketLocationCommand } = require('@aws-sdk/client-s3');
2
+
3
+ async function getBucketRegion(bucketName) {
4
+ const c = new S3Client({ region: global.artillery.awsRegion || 'us-east-1' });
5
+ const command = new GetBucketLocationCommand({
6
+ Bucket: bucketName
7
+ });
8
+
9
+ const response = await c.send(command);
10
+
11
+ // Buckets is us-east-1 have a LocationConstraint of null
12
+ const location = response.LocationConstraint || 'us-east-1';
13
+ return location;
14
+ }
15
+
16
+ module.exports = {
17
+ getBucketRegion
18
+ };
@@ -0,0 +1,28 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ const debug = require('debug')('util:aws:getSSOCredentials');
6
+ const { fromSSO } = require('@aws-sdk/credential-providers');
7
+
8
+ module.exports = getSSOCredentials;
9
+
10
+ // If SSO is in use and we can acquire fresh credentials, return [true, credentials object]
11
+ // If SSO is in use, but the session is stale, we return [true, {}]
12
+ // If SSO is not in use we return [false, null]
13
+
14
+ async function getSSOCredentials() {
15
+ debug('Trying AWS SSO');
16
+ try {
17
+ const credentials = await fromSSO()();
18
+ return [true, credentials];
19
+ } catch (err) {
20
+ debug(err);
21
+
22
+ if (/SSO.+expired/.test(err.message)) {
23
+ return [true, null];
24
+ } else {
25
+ return [false, null];
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,26 @@
1
+ const { loadConfig } = require('@smithy/node-config-provider');
2
+ const {
3
+ NODE_REGION_CONFIG_FILE_OPTIONS,
4
+ NODE_REGION_CONFIG_OPTIONS
5
+ } = require('@smithy/config-resolver');
6
+ const debug = require('debug')('util:aws:get-default-region');
7
+
8
+ let defaultRegionAlreadyChecked = false;
9
+ let currentDefaultRegion = null;
10
+
11
+ module.exports = async function getDefaultRegion() {
12
+ if (!defaultRegionAlreadyChecked) {
13
+ try {
14
+ currentDefaultRegion = await loadConfig(
15
+ NODE_REGION_CONFIG_OPTIONS,
16
+ NODE_REGION_CONFIG_FILE_OPTIONS
17
+ )();
18
+ } catch (err) {
19
+ debug('default region check:', err);
20
+ } finally {
21
+ defaultRegionAlreadyChecked = true;
22
+ }
23
+ }
24
+
25
+ return currentDefaultRegion;
26
+ };
@@ -0,0 +1,15 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
+
5
+ const { STSClient, GetCallerIdentityCommand } = require('@aws-sdk/client-sts');
6
+
7
+ module.exports = async function whoami() {
8
+ const sts = new STSClient();
9
+ try {
10
+ const response = await sts.send(new GetCallerIdentityCommand({}));
11
+ return response;
12
+ } catch (stsErr) {
13
+ return stsErr;
14
+ }
15
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ SQS_QUEUES_NAME_PREFIX: 'artilleryio_test_metrics',
3
+ S3_BUCKET_NAME_PREFIX: 'artilleryio-test-data',
4
+ ECS_WORKER_ROLE_NAME: 'artilleryio-ecs-worker-role',
5
+
6
+ ARTILLERY_CLUSTER_NAME: 'artilleryio-cluster'
7
+ };
@@ -0,0 +1,219 @@
1
+ AWSTemplateFormatVersion: "2010-09-09"
2
+ Description: "Template to create an IAM Role with an attached policy that provides all necessary permissions for Artillery.io to run distributed tests on AWS Fargate.
3
+ By default the IAM role is configured to trust your AWS account, meaning it will allow any IAM User, Role or service from your account to assume it. You can restrict the role to allow only by a specific IAM user or role to assume it by filling out the appropriate parameter value below."
4
+
5
+ Metadata:
6
+ AWS::CloudFormation::Interface:
7
+ ParameterGroups:
8
+ - Label:
9
+ default: "Restrict to specific IAM User (optional)"
10
+ Parameters:
11
+ - User
12
+ - Label:
13
+ default: "Restrict to specific IAM Role (optional)"
14
+ Parameters:
15
+ - Role
16
+ ParameterLabels:
17
+ User:
18
+ default: "IAM user name or ARN"
19
+ Role:
20
+ default: "IAM role name or ARN"
21
+
22
+ Parameters:
23
+
24
+ User:
25
+ Type: String
26
+ Default: ""
27
+ Description: Use when you want to allow the created role to be assumed only by a specific IAM user (by default any user, role or service from your account will be allowed to assume it). Provide the user name or ARN.
28
+
29
+ Role:
30
+ Type: String
31
+ Default: ""
32
+ Description: Use when you want to allow the created role to be assumed only by a specific IAM role (by default any user, role or service from your account will be allowed to assume it). Provide the role name or ARN.
33
+
34
+ Conditions:
35
+ ShouldTrustAccount:
36
+ !And
37
+ - !Equals [!Ref User, ""]
38
+ - !Equals [!Ref Role, ""]
39
+ ShouldTrustUser:
40
+ !Not [!Equals [!Ref User, ""]]
41
+ IsUserArn:
42
+ !Equals [!Select [0, !Split [":", !Ref User]], "arn"]
43
+ ShouldTrustRole:
44
+ !Not [!Equals [!Ref Role, ""]]
45
+ IsRoleArn:
46
+ !Equals [!Select [0, !Split [":", !Ref Role]], "arn"]
47
+
48
+
49
+ Resources:
50
+ ArtilleryDistributedTestingFargateRole:
51
+ Type: "AWS::IAM::Role"
52
+ Properties:
53
+ RoleName: "ArtilleryDistributedTestingFargateRole"
54
+ AssumeRolePolicyDocument:
55
+ Version: "2012-10-17"
56
+ Statement:
57
+ - Effect: "Allow"
58
+ Principal:
59
+ AWS: [
60
+ !If [ShouldTrustAccount, !Ref "AWS::AccountId", !Ref "AWS::NoValue"],
61
+ !If [ShouldTrustUser, !If [IsUserArn, !Ref User, !Sub "arn:aws:iam::${AWS::AccountId}:user/${User}"], !Ref "AWS::NoValue"],
62
+ !If [ShouldTrustRole, !If [IsRoleArn, !Ref Role, !Sub "arn:aws:iam::${AWS::AccountId}:role/${Role}"], !Ref "AWS::NoValue"]
63
+ ]
64
+ Action: [
65
+ "sts:AssumeRole"
66
+ ]
67
+
68
+ Path: "/"
69
+ Policies:
70
+ - PolicyName: "ArtilleryDistributedTestingFargatePolicy"
71
+ PolicyDocument:
72
+ Version: "2012-10-17"
73
+ Statement:
74
+ - Sid: "CreateOrGetECSRole"
75
+ Effect: "Allow"
76
+ Action:
77
+ - "iam:CreateRole"
78
+ - "iam:GetRole"
79
+ - "iam:AttachRolePolicy"
80
+ - "iam:PassRole"
81
+ Resource:
82
+ Fn::Sub: "arn:aws:iam::${AWS::AccountId}:role/artilleryio-ecs-worker-role"
83
+ - Sid: "CreateECSPolicy"
84
+ Effect: "Allow"
85
+ Action:
86
+ - "iam:CreatePolicy"
87
+ Resource:
88
+ Fn::Sub: "arn:aws:iam::${AWS::AccountId}:policy/artilleryio-ecs-worker-policy"
89
+ - Effect: "Allow"
90
+ Action:
91
+ - "iam:CreateServiceLinkedRole"
92
+ Resource:
93
+ - "arn:aws:iam::*:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS*"
94
+ Condition:
95
+ StringLike:
96
+ iam:AWSServiceName: "ecs.amazonaws.com"
97
+ - Effect: "Allow"
98
+ Action:
99
+ - "iam:PassRole"
100
+ Resource:
101
+ - Fn::Sub: "arn:aws:iam::${AWS::AccountId}:role/artilleryio-ecs-worker-role"
102
+ - Sid: "SQSPermissions"
103
+ Effect: "Allow"
104
+ Action:
105
+ - "sqs:*"
106
+ Resource:
107
+ Fn::Sub: "arn:aws:sqs:*:${AWS::AccountId}:artilleryio*"
108
+ - Sid: "SQSListQueues"
109
+ Effect: "Allow"
110
+ Action:
111
+ - "sqs:ListQueues"
112
+ Resource: "*"
113
+ - Sid: "ECSPermissionsGeneral"
114
+ Effect: "Allow"
115
+ Action:
116
+ - "ecs:ListClusters"
117
+ - "ecs:CreateCluster"
118
+ - "ecs:RegisterTaskDefinition"
119
+ - "ecs:DeregisterTaskDefinition"
120
+ Resource: "*"
121
+ - Sid: "ECSPermissionsScopedToCluster"
122
+ Effect: "Allow"
123
+ Action:
124
+ - "ecs:DescribeClusters"
125
+ - "ecs:ListContainerInstances"
126
+ Resource:
127
+ Fn::Sub: "arn:aws:ecs:*:${AWS::AccountId}:cluster/*"
128
+ - Sid: "ECSPermissionsScopedWithCondition"
129
+ Effect: "Allow"
130
+ Action:
131
+ - "ecs:SubmitTaskStateChange"
132
+ - "ecs:DescribeTasks"
133
+ - "ecs:ListTasks"
134
+ - "ecs:ListTaskDefinitions"
135
+ - "ecs:DescribeTaskDefinition"
136
+ - "ecs:StartTask"
137
+ - "ecs:StopTask"
138
+ - "ecs:RunTask"
139
+ Condition:
140
+ ArnEquals:
141
+ ecs:cluster:
142
+ Fn::Sub: "arn:aws:ecs:*:${AWS::AccountId}:cluster/*"
143
+ Resource: "*"
144
+ - Sid: "S3Permissions"
145
+ Effect: "Allow"
146
+ Action:
147
+ - "s3:CreateBucket"
148
+ - "s3:DeleteObject"
149
+ - "s3:GetObject"
150
+ - "s3:GetObjectAcl"
151
+ - "s3:GetObjectTagging"
152
+ - "s3:GetObjectVersion"
153
+ - "s3:PutObject"
154
+ - "s3:PutObjectAcl"
155
+ - "s3:ListBucket"
156
+ - "s3:GetBucketLocation"
157
+ - "s3:GetBucketLogging"
158
+ - "s3:GetBucketPolicy"
159
+ - "s3:GetBucketTagging"
160
+ - "s3:PutBucketPolicy"
161
+ - "s3:PutBucketTagging"
162
+ - "s3:PutMetricsConfiguration"
163
+ - "s3:GetLifecycleConfiguration"
164
+ - "s3:PutLifecycleConfiguration"
165
+ Resource:
166
+ - "arn:aws:s3:::artilleryio-test-data-*"
167
+ - "arn:aws:s3:::artilleryio-test-data-*/*"
168
+ - Sid: "LogsPermissions"
169
+ Effect: "Allow"
170
+ Action:
171
+ - "logs:PutRetentionPolicy"
172
+ Resource:
173
+ - Fn::Sub: "arn:aws:logs:*:${AWS::AccountId}:log-group:artilleryio-log-group/*"
174
+ - Effect: "Allow"
175
+ Action:
176
+ - "secretsmanager:GetSecretValue"
177
+ Resource:
178
+ - Fn::Sub: "arn:aws:secretsmanager:*:${AWS::AccountId}:secret:artilleryio/*"
179
+ - Effect: "Allow"
180
+ Action:
181
+ - "ssm:PutParameter"
182
+ - "ssm:GetParameter"
183
+ - "ssm:GetParameters"
184
+ - "ssm:DeleteParameter"
185
+ - "ssm:DescribeParameters"
186
+ - "ssm:GetParametersByPath"
187
+ Resource:
188
+ - Fn::Sub: "arn:aws:ssm:us-east-1:${AWS::AccountId}:parameter/artilleryio/*"
189
+ - Fn::Sub: "arn:aws:ssm:us-east-2:${AWS::AccountId}:parameter/artilleryio/*"
190
+ - Fn::Sub: "arn:aws:ssm:us-west-1:${AWS::AccountId}:parameter/artilleryio/*"
191
+ - Fn::Sub: "arn:aws:ssm:us-west-2:${AWS::AccountId}:parameter/artilleryio/*"
192
+ - Fn::Sub: "arn:aws:ssm:ca-central-1:${AWS::AccountId}:parameter/artilleryio/*"
193
+ - Fn::Sub: "arn:aws:ssm:eu-west-1:${AWS::AccountId}:parameter/artilleryio/*"
194
+ - Fn::Sub: "arn:aws:ssm:eu-west-2:${AWS::AccountId}:parameter/artilleryio/*"
195
+ - Fn::Sub: "arn:aws:ssm:eu-west-3:${AWS::AccountId}:parameter/artilleryio/*"
196
+ - Fn::Sub: "arn:aws:ssm:eu-central-1:${AWS::AccountId}:parameter/artilleryio/*"
197
+ - Fn::Sub: "arn:aws:ssm:eu-north-1:${AWS::AccountId}:parameter/artilleryio/*"
198
+ - Fn::Sub: "arn:aws:ssm:ap-south-1:${AWS::AccountId}:parameter/artilleryio/*"
199
+ - Fn::Sub: "arn:aws:ssm:ap-east-1:${AWS::AccountId}:parameter/artilleryio/*"
200
+ - Fn::Sub: "arn:aws:ssm:ap-northeast-1:${AWS::AccountId}:parameter/artilleryio/*"
201
+ - Fn::Sub: "arn:aws:ssm:ap-northeast-2:${AWS::AccountId}:parameter/artilleryio/*"
202
+ - Fn::Sub: "arn:aws:ssm:ap-southeast-1:${AWS::AccountId}:parameter/artilleryio/*"
203
+ - Fn::Sub: "arn:aws:ssm:ap-southeast-2:${AWS::AccountId}:parameter/artilleryio/*"
204
+ - Fn::Sub: "arn:aws:ssm:me-south-1:${AWS::AccountId}:parameter/artilleryio/*"
205
+ - Fn::Sub: "arn:aws:ssm:sa-east-1:${AWS::AccountId}:parameter/artilleryio/*"
206
+ - Effect: "Allow"
207
+ Action:
208
+ - "ec2:DescribeRouteTables"
209
+ - "ec2:DescribeVpcs"
210
+ - "ec2:DescribeSubnets"
211
+ Resource: "*"
212
+
213
+ Outputs:
214
+ RoleArn:
215
+ Description: "ARN of the created IAM Role"
216
+ Value:
217
+ Fn::GetAtt:
218
+ - "ArtilleryDistributedTestingFargateRole"
219
+ - "Arn"
@@ -0,0 +1,125 @@
1
+ AWSTemplateFormatVersion: "2010-09-09"
2
+ Description: Template to create an IAM Role with an attached policy that provides all necessary permissions for Artillery.io to run distributed tests on AWS Lambda. By default the IAM role is configured to trust your AWS account, meaning it will allow any AWS principal (e.g. IAM User, IAM Role) to assume it. You can restrict the role to allow only by a specific IAM user or role to assume it by filling out the appropriate parameter value below.
3
+
4
+ Metadata:
5
+ AWS::CloudFormation::Interface:
6
+ ParameterGroups:
7
+ - Label:
8
+ default: "Restrict to specific IAM User (optional)"
9
+ Parameters:
10
+ - User
11
+ - Label:
12
+ default: "Restrict to specific IAM Role (optional)"
13
+ Parameters:
14
+ - Role
15
+ ParameterLabels:
16
+ User:
17
+ default: "IAM user name or ARN"
18
+ Role:
19
+ default: "IAM role name or ARN"
20
+
21
+ Parameters:
22
+
23
+ User:
24
+ Type: String
25
+ Default: ""
26
+ Description: Use when you want to allow the created role to be assumed only by a specific IAM user (by default any user, role or service from your account will be allowed to assume it). Provide the user name or ARN.
27
+
28
+ Role:
29
+ Type: String
30
+ Default: ""
31
+ Description: Use when you want to allow the created role to be assumed only by a specific IAM role (by default any user, role or service from your account will be allowed to assume it). Provide the role name or ARN.
32
+
33
+ Conditions:
34
+ ShouldTrustAccount:
35
+ !And
36
+ - !Equals [!Ref User, ""]
37
+ - !Equals [!Ref Role, ""]
38
+ ShouldTrustUser:
39
+ !Not [!Equals [!Ref User, ""]]
40
+ IsUserArn:
41
+ !Equals [!Select [0, !Split [":", !Ref User]], "arn"]
42
+ ShouldTrustRole:
43
+ !Not [!Equals [!Ref Role, ""]]
44
+ IsRoleArn:
45
+ !Equals [!Select [0, !Split [":", !Ref Role]], "arn"]
46
+
47
+
48
+
49
+ Resources:
50
+ ArtilleryDistributedTestingLambdaRole:
51
+ Type: "AWS::IAM::Role"
52
+ Properties:
53
+ RoleName: "ArtilleryDistributedTestingLambdaRole"
54
+ AssumeRolePolicyDocument:
55
+ Version: "2012-10-17"
56
+ Statement:
57
+ - Effect: "Allow"
58
+ Principal:
59
+ AWS: [
60
+ !If [ShouldTrustAccount, !Ref "AWS::AccountId", !Ref "AWS::NoValue"],
61
+ !If [ShouldTrustUser, !If [IsUserArn, !Ref User, !Sub "arn:aws:iam::${AWS::AccountId}:user/${User}"], !Ref "AWS::NoValue"],
62
+ !If [ShouldTrustRole, !If [IsRoleArn, !Ref Role, !Sub "arn:aws:iam::${AWS::AccountId}:role/${Role}"], !Ref "AWS::NoValue"]
63
+ ]
64
+ Action: ["sts:AssumeRole"]
65
+
66
+ Path: "/"
67
+ Policies:
68
+ - PolicyName: ArtilleryDistributedTestingLambdaPolicy
69
+ PolicyDocument:
70
+ Version: "2012-10-17"
71
+ Statement:
72
+ - Sid: CreateOrGetLambdaRole
73
+ Effect: Allow
74
+ Action:
75
+ - iam:CreateRole
76
+ - iam:GetRole
77
+ - iam:PassRole
78
+ - iam:AttachRolePolicy
79
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/artilleryio-default-lambda-role-*"
80
+ - Sid: CreateLambdaPolicy
81
+ Effect: Allow
82
+ Action:
83
+ - iam:CreatePolicy
84
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:policy/artilleryio-lambda-policy-*"
85
+ - Sid: SQSPermissions
86
+ Effect: Allow
87
+ Action:
88
+ - sqs:*
89
+ Resource: !Sub "arn:aws:sqs:*:${AWS::AccountId}:artilleryio*"
90
+ - Sid: SQSListQueues
91
+ Effect: Allow
92
+ Action:
93
+ - sqs:ListQueues
94
+ Resource: "*"
95
+ - Sid: LambdaPermissions
96
+ Effect: Allow
97
+ Action:
98
+ - lambda:InvokeFunction
99
+ - lambda:CreateFunction
100
+ - lambda:DeleteFunction
101
+ - lambda:GetFunctionConfiguration
102
+ Resource: !Sub "arn:aws:lambda:*:${AWS::AccountId}:function:artilleryio-*"
103
+ - Sid: EcrPullImagePermissions
104
+ Effect: Allow
105
+ Action:
106
+ - ecr:GetDownloadUrlForLayer
107
+ - ecr:BatchGetImage
108
+ Resource: "arn:aws:ecr:*:248481025674:repository/artillery-worker"
109
+ - Sid: S3Permissions
110
+ Effect: Allow
111
+ Action:
112
+ - s3:CreateBucket
113
+ - s3:DeleteObject
114
+ - s3:GetObject
115
+ - s3:PutObject
116
+ - s3:ListBucket
117
+ - s3:GetLifecycleConfiguration
118
+ - s3:PutLifecycleConfiguration
119
+ Resource:
120
+ - !Sub "arn:aws:s3:::artilleryio-test-data-*"
121
+ - !Sub "arn:aws:s3:::artilleryio-test-data-*/*"
122
+ Outputs:
123
+ RoleArn:
124
+ Description: ARN of the IAM Role for Artillery.io Lambda functions
125
+ Value: !GetAtt ArtilleryDistributedTestingLambdaRole.Arn