aws-architect 6.7.141 → 6.7.142

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.
@@ -3,6 +3,7 @@ let glob = require('glob');
3
3
  let path = require('path');
4
4
  const { createHash } = require('crypto');
5
5
  const { lookup } = require('mime-types');
6
+ const { S3Client, HeadBucketCommand, CreateBucketCommand, PutPublicAccessBlockCommand, PutBucketLifecycleConfigurationCommand } = require('@aws-sdk/client-s3');
6
7
 
7
8
  const contentTypeMappingConst = {
8
9
  '.ico': 'image/x-icon',
@@ -154,43 +155,48 @@ class BucketManager {
154
155
  }
155
156
 
156
157
  async ensureBucketExists(bucket) {
158
+ const region = this.S3Manager.config.region;
159
+ const s3Client = new S3Client({ region });
160
+
157
161
  const bucketLifecycleConfigurationParams = {
158
162
  Bucket: bucket,
159
163
  LifecycleConfiguration: {
160
164
  Rules: [{
161
165
  ID: 'AwsArchitect-AutoDeleteOldArtifacts',
162
- Expiration: {
163
- Days: 31
164
- },
165
- Prefix: '',
166
- NoncurrentVersionExpiration: {
167
- NoncurrentDays: 5
168
- },
169
- AbortIncompleteMultipartUpload: {
170
- DaysAfterInitiation: 5
171
- },
166
+ Filter: { Prefix: '' },
167
+ Expiration: { Days: 31 },
168
+ NoncurrentVersionExpiration: { NoncurrentDays: 5 },
169
+ AbortIncompleteMultipartUpload: { DaysAfterInitiation: 5 },
172
170
  Status: 'Enabled'
173
171
  }]
174
172
  }
175
173
  };
176
174
 
177
175
  try {
178
- await this.S3Manager.headBucket({ Bucket: bucket }).promise();
176
+ await s3Client.send(new HeadBucketCommand({ Bucket: bucket }));
179
177
  } catch (error) {
180
- if (error.code !== 'NotFound') {
178
+ if (error.name !== 'NotFound') {
181
179
  throw { title: 'Failed to validate deployment bucket is available', error, bucket };
182
180
  }
181
+ }
183
182
 
184
- const params = { Bucket: bucket };
185
- if (this.S3Manager.config.region !== 'us-east-1') {
186
- params.CreateBucketConfiguration = { LocationConstraint: this.S3Manager.config.region };
183
+ const params = { Bucket: bucket };
184
+ if (region !== 'us-east-1') {
185
+ params.CreateBucketConfiguration = { LocationConstraint: region };
186
+ }
187
+ try {
188
+ console.log(`[AWS Architect] (S3) - Cretaing deployment bucket because it does not exist exist: ${bucket}`);
189
+ await s3Client.send(new CreateBucketCommand(params));
190
+ } catch (error) {
191
+ if (error.name === 'BucketAlreadyExists') {
192
+ return;
187
193
  }
188
- await this.S3Manager.createBucket(params).promise();
189
- await this.S3Manager.putPublicAccessBlock({
190
- Bucket: bucket, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true }
191
- }).promise();
192
- await this.S3Manager.putBucketLifecycleConfiguration(bucketLifecycleConfigurationParams).promise();
194
+ throw error;
193
195
  }
196
+ await s3Client.send(new PutPublicAccessBlockCommand({
197
+ Bucket: bucket, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true }
198
+ }));
199
+ await s3Client.send(new PutBucketLifecycleConfigurationCommand(bucketLifecycleConfigurationParams));
194
200
  }
195
201
 
196
202
  // Ensures a path will be in unix format (that is, forward slash), also on Windows systems.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-architect",
3
- "version": "6.7.141",
3
+ "version": "6.7.142",
4
4
  "description": "AWS Architect is a node based tool to configure and deploy AWS-based microservices.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@aws-sdk/client-cloudformation": "^3.1000.0",
22
+ "@aws-sdk/client-s3": "^3.1000",
22
23
  "archiver": "^5.3.0",
23
24
  "body-parser": "^1.18.2",
24
25
  "commander": "^2.5.0",