@fishawack/lab-env 5.1.0 → 5.2.0-beta.2

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 (46) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/_Test/key.js +7 -2
  3. package/_Test/provision.js +9 -19
  4. package/_Test/s3.js +10 -6
  5. package/adonis/0/docker-compose.yml +2 -0
  6. package/adonis/0/nginx/CHANGELOG.md +3 -0
  7. package/adonis/0/nginx/nginx.conf +5 -1
  8. package/adonis/0/nginx/package.json +2 -2
  9. package/bitbucket-pipelines.yml +1 -1
  10. package/cli.js +1 -1
  11. package/commands/content.js +36 -25
  12. package/commands/create/cmds/deprovision.js +10 -2
  13. package/commands/create/cmds/provision.js +13 -2
  14. package/commands/create/libs/prompts.js +9 -0
  15. package/commands/create/libs/vars.js +67 -35
  16. package/commands/create/services/aws/cloudfront.js +17 -20
  17. package/commands/create/services/aws/ec2.js +2 -3
  18. package/commands/create/services/aws/elasticbeanstalk.js +11 -14
  19. package/commands/create/services/aws/iam.js +123 -65
  20. package/commands/create/services/aws/index.js +35 -35
  21. package/commands/create/services/aws/misc.js +6 -7
  22. package/commands/create/services/aws/s3.js +16 -16
  23. package/commands/create/templates/elasticbeanstalk/.ebextensions/misc/asg-self-healing.config +6 -0
  24. package/commands/create/templates/elasticbeanstalk/.ebextensions/misc/health-ignore-4xx.config +4 -0
  25. package/commands/test.js +11 -11
  26. package/core/0/package.json +1 -1
  27. package/craftcms/3/apache/package.json +1 -1
  28. package/craftcms/3/php/package.json +1 -1
  29. package/drupal/9/apache/package.json +1 -1
  30. package/drupal/9/php/package.json +1 -1
  31. package/globals.js +15 -0
  32. package/laravel/10/docker-compose.yml +2 -0
  33. package/laravel/8/docker-compose.yml +2 -0
  34. package/laravel/8/nginx/CHANGELOG.md +3 -0
  35. package/laravel/8/nginx/nginx.conf +5 -1
  36. package/laravel/8/nginx/package.json +2 -2
  37. package/laravel/8/php/package.json +1 -1
  38. package/laravel/9/docker-compose.yml +2 -0
  39. package/package.json +1 -1
  40. package/php/8.2/package.json +1 -1
  41. package/python/0/Dockerfile +8 -0
  42. package/python/0/docker-compose.yml +4 -1
  43. package/python/0/package.json +11 -0
  44. package/wordpress/0/package.json +1 -1
  45. package/wordpress/1/apache/package.json +1 -1
  46. package/wordpress/1/php/package.json +1 -1
@@ -18,17 +18,15 @@ const fs = require("fs");
18
18
  const { merge } = require("lodash");
19
19
  const { Spinner, poll } = require("../../libs/utilities");
20
20
  const { cloudfront } = require("../../libs/vars");
21
- const { createClient } = require("./misc.js");
22
21
 
23
22
  module.exports.createCloudFrontDistribution = async (
24
23
  name,
25
- account,
26
24
  tags = [],
27
25
  FunctionARNRequest = null,
28
26
  FunctionARNResponse = null,
29
27
  region = "us-east-1",
30
28
  ) => {
31
- const client = createClient(CloudFrontClient, account, region);
29
+ const client = new CloudFrontClient({});
32
30
 
33
31
  let OAI = await Spinner.prototype.simple(`Creating CloudFront OAI`, () => {
34
32
  return client.send(
@@ -59,7 +57,10 @@ module.exports.createCloudFrontDistribution = async (
59
57
  ),
60
58
  Tags: {
61
59
  Items: [
62
- { Key: "client", Value: account },
60
+ {
61
+ Key: "client",
62
+ Value: process.env.AWS_PROFILE,
63
+ },
63
64
  ].concat(tags),
64
65
  },
65
66
  },
@@ -73,7 +74,6 @@ module.exports.createCloudFrontDistribution = async (
73
74
  () => {
74
75
  return module.exports.waitForCloudFrontDistribution(
75
76
  res.Distribution.Id,
76
- account,
77
77
  );
78
78
  },
79
79
  );
@@ -112,8 +112,8 @@ module.exports.createCloudFrontDistribution = async (
112
112
  return res;
113
113
  };
114
114
 
115
- module.exports.removeCloudFrontDistribution = async (Id, account) => {
116
- const client = createClient(CloudFrontClient, account);
115
+ module.exports.removeCloudFrontDistribution = async (Id) => {
116
+ const client = new CloudFrontClient({});
117
117
 
118
118
  let res = await Spinner.prototype.simple(
119
119
  `Retrieving the CloudFront distribution ${Id}`,
@@ -147,7 +147,6 @@ module.exports.removeCloudFrontDistribution = async (Id, account) => {
147
147
  () => {
148
148
  return module.exports.waitForCloudFrontDistribution(
149
149
  res.Distribution.Id,
150
- account,
151
150
  );
152
151
  },
153
152
  );
@@ -180,8 +179,8 @@ module.exports.removeCloudFrontDistribution = async (Id, account) => {
180
179
  });
181
180
  };
182
181
 
183
- module.exports.waitForCloudFrontDistribution = async (Id, account) => {
184
- const client = createClient(CloudFrontClient, account);
182
+ module.exports.waitForCloudFrontDistribution = async (Id) => {
183
+ const client = new CloudFrontClient({});
185
184
 
186
185
  await poll(
187
186
  async () => await client.send(new GetDistributionCommand({ Id })),
@@ -189,8 +188,8 @@ module.exports.waitForCloudFrontDistribution = async (Id, account) => {
189
188
  );
190
189
  };
191
190
 
192
- module.exports.createCloudFrontFunction = async (name, account, fn, config) => {
193
- const client = createClient(CloudFrontClient, account);
191
+ module.exports.createCloudFrontFunction = async (name, fn, config) => {
192
+ const client = new CloudFrontClient({});
194
193
 
195
194
  let FunctionConfig = {
196
195
  Comment: `lab-env provisioned cloudfront function for project ${name} using code snippet ${fn}.js`,
@@ -261,8 +260,8 @@ module.exports.createCloudFrontFunction = async (name, account, fn, config) => {
261
260
  return res;
262
261
  };
263
262
 
264
- module.exports.removeCloudFrontFunction = async (name, account) => {
265
- const client = createClient(CloudFrontClient, account);
263
+ module.exports.removeCloudFrontFunction = async (name) => {
264
+ const client = new CloudFrontClient({});
266
265
 
267
266
  let res = await Spinner.prototype.simple(
268
267
  `Retrieving CloudFront function`,
@@ -287,8 +286,8 @@ module.exports.removeCloudFrontFunction = async (name, account) => {
287
286
  return res;
288
287
  };
289
288
 
290
- module.exports.setCloudFrontFunctionAssociation = async (Id, account) => {
291
- const client = createClient(CloudFrontClient, account);
289
+ module.exports.setCloudFrontFunctionAssociation = async (Id) => {
290
+ const client = new CloudFrontClient({});
292
291
 
293
292
  let res = await Spinner.prototype.simple(
294
293
  `Retrieving CloudFront distribution`,
@@ -339,14 +338,13 @@ module.exports.setCloudFrontFunctionAssociation = async (Id, account) => {
339
338
  () => {
340
339
  return module.exports.waitForCloudFrontDistribution(
341
340
  res.Distribution.Id,
342
- account,
343
341
  );
344
342
  },
345
343
  );
346
344
  };
347
345
 
348
- module.exports.removeCloudFrontFunctionAssociation = async (Id, account) => {
349
- const client = createClient(CloudFrontClient, account);
346
+ module.exports.removeCloudFrontFunctionAssociation = async (Id) => {
347
+ const client = new CloudFrontClient({});
350
348
 
351
349
  let res = await Spinner.prototype.simple(
352
350
  `Retrieving CloudFront distribution`,
@@ -379,7 +377,6 @@ module.exports.removeCloudFrontFunctionAssociation = async (Id, account) => {
379
377
  () => {
380
378
  return module.exports.waitForCloudFrontDistribution(
381
379
  res.Distribution.Id,
382
- account,
383
380
  );
384
381
  },
385
382
  );
@@ -1,9 +1,8 @@
1
1
  const { EC2Client, DescribeKeyPairsCommand } = require("@aws-sdk/client-ec2");
2
2
  const { Spinner } = require("../../libs/utilities");
3
- const { createClient } = require("./misc.js");
4
3
 
5
- module.exports.getKeyPair = async (KeyName, account) => {
6
- const client = createClient(EC2Client, account);
4
+ module.exports.getKeyPair = async (KeyName) => {
5
+ const client = new EC2Client({});
7
6
 
8
7
  let res = await Spinner.prototype.simple(
9
8
  `Retrieving the KeyPair ${KeyName}`,
@@ -11,10 +11,9 @@ const {
11
11
  } = require("@aws-sdk/client-elastic-beanstalk");
12
12
  const { Spinner, poll } = require("../../libs/utilities");
13
13
  const { eb } = require("../../libs/vars");
14
- const { createClient } = require("./misc.js");
15
14
 
16
- module.exports.createElasticBeanstalkApplication = async (name, account) => {
17
- const client = createClient(ElasticBeanstalkClient, account);
15
+ module.exports.createElasticBeanstalkApplication = async (name) => {
16
+ const client = new ElasticBeanstalkClient({});
18
17
 
19
18
  let res = await Spinner.prototype.simple(
20
19
  `Creating elasticbeanstalk application ${name}`,
@@ -30,14 +29,13 @@ module.exports.createElasticBeanstalkApplication = async (name, account) => {
30
29
 
31
30
  module.exports.createElasticBeanstalkEnvironment = async (
32
31
  name,
33
- account,
34
32
  { language },
35
33
  ApplicationName,
36
34
  OptionSettings,
37
35
  CNAMEPrefix,
38
36
  tags = [],
39
37
  ) => {
40
- const client = createClient(ElasticBeanstalkClient, account);
38
+ const client = new ElasticBeanstalkClient({});
41
39
 
42
40
  const solutions = await Spinner.prototype.simple(
43
41
  `Retrieving available solution stacks`,
@@ -70,7 +68,9 @@ module.exports.createElasticBeanstalkEnvironment = async (
70
68
  SolutionStackName,
71
69
  OptionSettings,
72
70
  CNAMEPrefix,
73
- Tags: [{ Key: "client", Value: account }].concat(tags),
71
+ Tags: [
72
+ { Key: "client", Value: process.env.AWS_PROFILE },
73
+ ].concat(tags),
74
74
  }),
75
75
  );
76
76
  },
@@ -81,7 +81,6 @@ module.exports.createElasticBeanstalkEnvironment = async (
81
81
  () => {
82
82
  return module.exports.waitForElasticBeanstalkEnvironment(
83
83
  name,
84
- account,
85
84
  "Ready",
86
85
  "Terminated",
87
86
  );
@@ -93,11 +92,10 @@ module.exports.createElasticBeanstalkEnvironment = async (
93
92
 
94
93
  module.exports.waitForElasticBeanstalkEnvironment = async (
95
94
  name,
96
- account,
97
95
  waitFor = "Ready",
98
96
  failIf,
99
97
  ) => {
100
- const client = createClient(ElasticBeanstalkClient, account);
98
+ const client = new ElasticBeanstalkClient({});
101
99
 
102
100
  const res = await poll(
103
101
  async () =>
@@ -115,8 +113,8 @@ module.exports.waitForElasticBeanstalkEnvironment = async (
115
113
  return res;
116
114
  };
117
115
 
118
- module.exports.removeElasticBeanstalkApplication = async (name, account) => {
119
- const client = createClient(ElasticBeanstalkClient, account);
116
+ module.exports.removeElasticBeanstalkApplication = async (name) => {
117
+ const client = new ElasticBeanstalkClient({});
120
118
 
121
119
  await Spinner.prototype.simple(
122
120
  `Removing elasticbeanstalk application ${name}`,
@@ -128,8 +126,8 @@ module.exports.removeElasticBeanstalkApplication = async (name, account) => {
128
126
  );
129
127
  };
130
128
 
131
- module.exports.removeElasticBeanstalkEnvironment = async (name, account) => {
132
- const client = createClient(ElasticBeanstalkClient, account);
129
+ module.exports.removeElasticBeanstalkEnvironment = async (name) => {
130
+ const client = new ElasticBeanstalkClient({});
133
131
 
134
132
  await Spinner.prototype.simple(
135
133
  `Removing elasticbeanstalk environment ${name}`,
@@ -145,7 +143,6 @@ module.exports.removeElasticBeanstalkEnvironment = async (name, account) => {
145
143
  () => {
146
144
  return module.exports.waitForElasticBeanstalkEnvironment(
147
145
  name,
148
- account,
149
146
  "Terminated",
150
147
  );
151
148
  },
@@ -17,10 +17,9 @@ const {
17
17
  PutRolePolicyCommand,
18
18
  } = require("@aws-sdk/client-iam");
19
19
  const { Spinner } = require("../../libs/utilities");
20
- const { createClient } = require("./misc.js");
21
20
 
22
- module.exports.createIAMUser = async (UserName, account, tags = []) => {
23
- const client = createClient(IAMClient, account);
21
+ module.exports.createIAMUser = async (UserName, tags = []) => {
22
+ const client = new IAMClient({});
24
23
 
25
24
  let res;
26
25
 
@@ -31,7 +30,9 @@ module.exports.createIAMUser = async (UserName, account, tags = []) => {
31
30
  return client.send(
32
31
  new CreateUserCommand({
33
32
  UserName,
34
- Tags: [{ Key: "client", Value: account }].concat(tags),
33
+ Tags: [
34
+ { Key: "client", Value: process.env.AWS_PROFILE },
35
+ ].concat(tags),
35
36
  }),
36
37
  );
37
38
  },
@@ -48,18 +49,18 @@ module.exports.createIAMUser = async (UserName, account, tags = []) => {
48
49
  return res;
49
50
  };
50
51
 
51
- module.exports.createFWIAMUser = async (UserName, account, permissions) => {
52
- await module.exports.createIAMUser(UserName, account);
52
+ module.exports.createFWIAMUser = async (UserName, permissions) => {
53
+ await module.exports.createIAMUser(UserName);
53
54
 
54
- await module.exports.syncFWIAMPolicies(UserName, account, permissions);
55
+ await module.exports.syncFWIAMPolicies(UserName, permissions);
55
56
 
56
- let res = await module.exports.createAccessKeySafe(UserName, account);
57
+ let res = await module.exports.createAccessKeySafe(UserName);
57
58
 
58
59
  return res;
59
60
  };
60
61
 
61
- module.exports.removeIAMUser = async (UserName, account) => {
62
- const client = createClient(IAMClient, account);
62
+ module.exports.removeIAMUser = async (UserName) => {
63
+ const client = new IAMClient({});
63
64
 
64
65
  let res;
65
66
 
@@ -71,9 +72,9 @@ module.exports.removeIAMUser = async (UserName, account) => {
71
72
  },
72
73
  );
73
74
 
74
- await module.exports.removeAllIAMPolicies(UserName, account);
75
+ await module.exports.removeAllIAMPolicies(UserName);
75
76
 
76
- await module.exports.removeAllAccessKeys(UserName, account);
77
+ await module.exports.removeAllAccessKeys(UserName);
77
78
 
78
79
  res = await Spinner.prototype.simple(
79
80
  `Removing IAM user ${UserName}`,
@@ -88,8 +89,8 @@ module.exports.removeIAMUser = async (UserName, account) => {
88
89
  return res;
89
90
  };
90
91
 
91
- module.exports.attachIAMPolicy = async (UserName, account, policy) => {
92
- const client = createClient(IAMClient, account);
92
+ module.exports.attachIAMPolicy = async (UserName, policy) => {
93
+ const client = new IAMClient({});
93
94
 
94
95
  let res = await Spinner.prototype.simple(
95
96
  `Attaching IAM policy ${policy}`,
@@ -105,10 +106,9 @@ module.exports.attachIAMPolicy = async (UserName, account, policy) => {
105
106
 
106
107
  module.exports.syncFWIAMPolicies = async (
107
108
  UserName,
108
- account,
109
109
  permissions = ["auto-content", "deploy-static"],
110
110
  ) => {
111
- await module.exports.removeAllIAMPolicies(UserName, account);
111
+ await module.exports.removeAllIAMPolicies(UserName);
112
112
 
113
113
  if (
114
114
  permissions.includes("auto-content") ||
@@ -116,7 +116,6 @@ module.exports.syncFWIAMPolicies = async (
116
116
  ) {
117
117
  await module.exports.attachIAMPolicy(
118
118
  UserName,
119
- account,
120
119
  "arn:aws:iam::aws:policy/AmazonS3FullAccess",
121
120
  );
122
121
  }
@@ -124,7 +123,6 @@ module.exports.syncFWIAMPolicies = async (
124
123
  if (permissions.includes("deploy-static")) {
125
124
  await module.exports.attachIAMPolicy(
126
125
  UserName,
127
- account,
128
126
  "arn:aws:iam::aws:policy/CloudFrontFullAccess",
129
127
  );
130
128
  }
@@ -132,13 +130,11 @@ module.exports.syncFWIAMPolicies = async (
132
130
  if (permissions.includes("deploy-fullstack")) {
133
131
  await module.exports.attachIAMPolicy(
134
132
  UserName,
135
- account,
136
133
  "arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk",
137
134
  );
138
135
 
139
136
  await module.exports.attachIAMPolicy(
140
137
  UserName,
141
- account,
142
138
  "arn:aws:iam::aws:policy/AmazonOpenSearchServiceFullAccess",
143
139
  );
144
140
  }
@@ -146,14 +142,13 @@ module.exports.syncFWIAMPolicies = async (
146
142
  if (permissions.includes("manage-users")) {
147
143
  await module.exports.attachIAMPolicy(
148
144
  UserName,
149
- account,
150
145
  "arn:aws:iam::aws:policy/IAMFullAccess",
151
146
  );
152
147
  }
153
148
  };
154
149
 
155
- module.exports.removeIAMPolicy = async (UserName, account, policy) => {
156
- const client = createClient(IAMClient, account);
150
+ module.exports.removeIAMPolicy = async (UserName, policy) => {
151
+ const client = new IAMClient({});
157
152
 
158
153
  let res = await Spinner.prototype.simple(
159
154
  `Detaching IAM policy ${policy}`,
@@ -167,8 +162,8 @@ module.exports.removeIAMPolicy = async (UserName, account, policy) => {
167
162
  return res;
168
163
  };
169
164
 
170
- module.exports.listIAMPolicies = async (UserName, account) => {
171
- const client = createClient(IAMClient, account);
165
+ module.exports.listIAMPolicies = async (UserName) => {
166
+ const client = new IAMClient({});
172
167
 
173
168
  let res = await Spinner.prototype.simple(`Listing IAM policies`, () => {
174
169
  return client.send(new ListAttachedUserPoliciesCommand({ UserName }));
@@ -177,13 +172,12 @@ module.exports.listIAMPolicies = async (UserName, account) => {
177
172
  return res;
178
173
  };
179
174
 
180
- module.exports.removeAllIAMPolicies = async (UserName, account) => {
181
- let res = await module.exports.listIAMPolicies(UserName, account);
175
+ module.exports.removeAllIAMPolicies = async (UserName) => {
176
+ let res = await module.exports.listIAMPolicies(UserName);
182
177
 
183
178
  for (let i = 0; i < res.AttachedPolicies.length; i++) {
184
179
  await module.exports.removeIAMPolicy(
185
180
  UserName,
186
- account,
187
181
  res.AttachedPolicies[i].PolicyArn,
188
182
  );
189
183
  }
@@ -191,8 +185,8 @@ module.exports.removeAllIAMPolicies = async (UserName, account) => {
191
185
  return res;
192
186
  };
193
187
 
194
- module.exports.createAccessKey = async (UserName, account) => {
195
- const client = createClient(IAMClient, account);
188
+ module.exports.createAccessKey = async (UserName) => {
189
+ const client = new IAMClient({});
196
190
 
197
191
  let res = await Spinner.prototype.simple(`Creating access key`, () => {
198
192
  return client.send(new CreateAccessKeyCommand({ UserName }));
@@ -201,8 +195,8 @@ module.exports.createAccessKey = async (UserName, account) => {
201
195
  return res;
202
196
  };
203
197
 
204
- module.exports.removeAccessKey = async (UserName, account, AccessKeyId) => {
205
- const client = createClient(IAMClient, account);
198
+ module.exports.removeAccessKey = async (UserName, AccessKeyId) => {
199
+ const client = new IAMClient({});
206
200
 
207
201
  let res = await Spinner.prototype.simple(
208
202
  `Removing access key ${AccessKeyId}`,
@@ -216,8 +210,8 @@ module.exports.removeAccessKey = async (UserName, account, AccessKeyId) => {
216
210
  return res;
217
211
  };
218
212
 
219
- module.exports.listAccessKeys = async (UserName, account) => {
220
- const client = createClient(IAMClient, account);
213
+ module.exports.listAccessKeys = async (UserName) => {
214
+ const client = new IAMClient({});
221
215
 
222
216
  let res = await Spinner.prototype.simple(`Listing access keys`, () => {
223
217
  return client.send(new ListAccessKeysCommand({ UserName }));
@@ -226,13 +220,12 @@ module.exports.listAccessKeys = async (UserName, account) => {
226
220
  return res;
227
221
  };
228
222
 
229
- module.exports.removeAllAccessKeys = async (UserName, account) => {
230
- let res = await module.exports.listAccessKeys(UserName, account);
223
+ module.exports.removeAllAccessKeys = async (UserName) => {
224
+ let res = await module.exports.listAccessKeys(UserName);
231
225
 
232
226
  for (let i = 0; i < res.AccessKeyMetadata.length; i++) {
233
227
  await module.exports.removeAccessKey(
234
228
  UserName,
235
- account,
236
229
  res.AccessKeyMetadata[i].AccessKeyId,
237
230
  );
238
231
  }
@@ -240,18 +233,18 @@ module.exports.removeAllAccessKeys = async (UserName, account) => {
240
233
  return res;
241
234
  };
242
235
 
243
- module.exports.createAccessKeySafe = async (UserName, account) => {
244
- let res = await module.exports.listAccessKeys(UserName, account);
236
+ module.exports.createAccessKeySafe = async (UserName) => {
237
+ let res = await module.exports.listAccessKeys(UserName);
245
238
 
246
239
  if (!res.AccessKeyMetadata.length) {
247
- res = await module.exports.createAccessKey(UserName, account);
240
+ res = await module.exports.createAccessKey(UserName);
248
241
  }
249
242
 
250
243
  return res;
251
244
  };
252
245
 
253
- module.exports.getRole = async (RoleName, account) => {
254
- const client = createClient(IAMClient, account);
246
+ module.exports.getRole = async (RoleName) => {
247
+ const client = new IAMClient({});
255
248
 
256
249
  let res = await Spinner.prototype.simple(
257
250
  `Retrieving the role ${RoleName}`,
@@ -263,12 +256,8 @@ module.exports.getRole = async (RoleName, account) => {
263
256
  return res;
264
257
  };
265
258
 
266
- module.exports.createRole = async (
267
- RoleName,
268
- account,
269
- AssumeRolePolicyDocument,
270
- ) => {
271
- const client = createClient(IAMClient, account);
259
+ module.exports.createRole = async (RoleName, AssumeRolePolicyDocument) => {
260
+ const client = new IAMClient({});
272
261
 
273
262
  let res = await Spinner.prototype.simple(
274
263
  `Creating the role ${RoleName}`,
@@ -282,8 +271,8 @@ module.exports.createRole = async (
282
271
  return res;
283
272
  };
284
273
 
285
- module.exports.createInstanceProfile = async (InstanceProfileName, account) => {
286
- const client = createClient(IAMClient, account);
274
+ module.exports.createInstanceProfile = async (InstanceProfileName) => {
275
+ const client = new IAMClient({});
287
276
 
288
277
  let res = await Spinner.prototype.simple(
289
278
  `Creating the instance profile ${InstanceProfileName}`,
@@ -300,9 +289,8 @@ module.exports.createInstanceProfile = async (InstanceProfileName, account) => {
300
289
  module.exports.attachRoleToInstanceProfile = async (
301
290
  RoleName,
302
291
  InstanceProfileName,
303
- account,
304
292
  ) => {
305
- const client = createClient(IAMClient, account);
293
+ const client = new IAMClient({});
306
294
 
307
295
  let res = await Spinner.prototype.simple(
308
296
  `Attaching role ${RoleName} to the instance profile ${InstanceProfileName}`,
@@ -319,8 +307,8 @@ module.exports.attachRoleToInstanceProfile = async (
319
307
  return res;
320
308
  };
321
309
 
322
- module.exports.attachRolePolicy = async (RoleName, account, PolicyArn) => {
323
- const client = createClient(IAMClient, account);
310
+ module.exports.attachRolePolicy = async (RoleName, PolicyArn) => {
311
+ const client = new IAMClient({});
324
312
 
325
313
  let res = await Spinner.prototype.simple(
326
314
  `Attaching Role policy ${PolicyArn}`,
@@ -336,11 +324,10 @@ module.exports.attachRolePolicy = async (RoleName, account, PolicyArn) => {
336
324
 
337
325
  module.exports.attachInlineRolePolicy = async (
338
326
  RoleName,
339
- account,
340
327
  PolicyName,
341
328
  PolicyDocument,
342
329
  ) => {
343
- const client = createClient(IAMClient, account);
330
+ const client = new IAMClient({});
344
331
 
345
332
  let res = await Spinner.prototype.simple(
346
333
  `Attaching Inline Role policy ${PolicyName}`,
@@ -358,15 +345,14 @@ module.exports.attachInlineRolePolicy = async (
358
345
  return res;
359
346
  };
360
347
 
361
- module.exports.ensureEBInstanceProfileExists = async (account) => {
348
+ module.exports.ensureEBInstanceProfileExists = async () => {
362
349
  const role = "aws-elasticbeanstalk-ec2-role";
363
350
 
364
351
  try {
365
- await module.exports.getRole(role, account);
352
+ await module.exports.getRole(role);
366
353
  } catch {
367
354
  await module.exports.createRole(
368
355
  role,
369
- account,
370
356
  JSON.stringify({
371
357
  Version: "2012-10-17",
372
358
  Statement: [
@@ -381,28 +367,24 @@ module.exports.ensureEBInstanceProfileExists = async (account) => {
381
367
  }),
382
368
  );
383
369
 
384
- await module.exports.createInstanceProfile(role, account);
385
- await module.exports.attachRoleToInstanceProfile(role, role, account);
370
+ await module.exports.createInstanceProfile(role);
371
+ await module.exports.attachRoleToInstanceProfile(role, role);
386
372
  }
387
373
 
388
374
  await module.exports.attachRolePolicy(
389
375
  role,
390
- account,
391
376
  "arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier",
392
377
  );
393
378
  await module.exports.attachRolePolicy(
394
379
  role,
395
- account,
396
380
  "arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier",
397
381
  );
398
382
  await module.exports.attachRolePolicy(
399
383
  role,
400
- account,
401
384
  "arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker",
402
385
  );
403
386
  await module.exports.attachInlineRolePolicy(
404
387
  role,
405
- account,
406
388
  "lab-env-elasticbeanstalk-describe-env",
407
389
  JSON.stringify({
408
390
  Version: "2012-10-17",
@@ -421,3 +403,79 @@ module.exports.ensureEBInstanceProfileExists = async (account) => {
421
403
  }),
422
404
  );
423
405
  };
406
+
407
+ module.exports.ensureEBManagedUpdateProfileExists = async () => {
408
+ const role = "lab-env-aws-elasticbeanstalk-service-role";
409
+
410
+ try {
411
+ await module.exports.getRole(role);
412
+ } catch {
413
+ await module.exports.createRole(
414
+ role,
415
+ JSON.stringify({
416
+ Version: "2012-10-17",
417
+ Statement: [
418
+ {
419
+ Sid: "ElasticBeanstalkAssumeRole",
420
+ Effect: "Allow",
421
+ Principal: {
422
+ Service: "elasticbeanstalk.amazonaws.com",
423
+ },
424
+ Action: "sts:AssumeRole",
425
+ Condition: {
426
+ StringEquals: {
427
+ "sts:ExternalId": "elasticbeanstalk",
428
+ },
429
+ },
430
+ },
431
+ {
432
+ Sid: "ElasticBeanstalkManagedUpdatesAssumeRole",
433
+ Effect: "Allow",
434
+ Principal: {
435
+ Service:
436
+ "managedupdates.elasticbeanstalk.amazonaws.com",
437
+ },
438
+ Action: "sts:AssumeRole",
439
+ },
440
+ ],
441
+ }),
442
+ );
443
+
444
+ await module.exports.createInstanceProfile(role);
445
+ await module.exports.attachRoleToInstanceProfile(role, role);
446
+ }
447
+
448
+ await module.exports.attachRolePolicy(
449
+ role,
450
+ "arn:aws:iam::aws:policy/service-role/AWSElasticBeanstalkEnhancedHealth",
451
+ );
452
+
453
+ await module.exports.attachRolePolicy(
454
+ role,
455
+ "arn:aws:iam::aws:policy/AWSElasticBeanstalkManagedUpdatesCustomerRolePolicy",
456
+ );
457
+
458
+ await module.exports.attachInlineRolePolicy(
459
+ role,
460
+ "lab-env-elasticbeanstalk-custom-managed-updates-permissions",
461
+ JSON.stringify({
462
+ Version: "2012-10-17",
463
+ Statement: [
464
+ {
465
+ Sid: "VisualEditor0",
466
+ Effect: "Allow",
467
+ Action: [
468
+ "es:DescribeDomain",
469
+ "es:DescribeElasticsearchDomain",
470
+ "es:ListTags",
471
+ "cloudwatch:PutMetricAlarm",
472
+ "cloudwatch:DeleteAlarms",
473
+ "cloudwatch:DescribeAlarms",
474
+ "cloudwatch:PutMetricData",
475
+ ],
476
+ Resource: "*",
477
+ },
478
+ ],
479
+ }),
480
+ );
481
+ };