aws-architect 6.6.28 → 6.6.32

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.
package/index.js CHANGED
@@ -4,7 +4,7 @@ let exec = require('child_process').exec;
4
4
  let fs = require('fs-extra');
5
5
  let path = require('path');
6
6
  let os = require('os');
7
- let uuid = require('uuid');
7
+ const shortUuid = require('short-uuid');
8
8
 
9
9
  let Server = require('./lib/server');
10
10
  let ApiGatewayManager = require('./lib/ApiGatewayManager');
@@ -47,7 +47,7 @@ AwsArchitect.prototype.publishZipArchive = async function(options = {}) {
47
47
  if (!options.zipFileName || !this.deploymentBucket || !options.sourceDirectory) {
48
48
  throw Error('The zipFileName, sourceDirectory, api options deploymentBucket must be specified.');
49
49
  }
50
- let tmpDir = path.join(os.tmpdir(), `zipDirectory-${uuid.v4()}`);
50
+ let tmpDir = path.join(os.tmpdir(), `zipDirectory-${shortUuid.generate()}`);
51
51
  await new Promise((resolve, reject) => { fs.stat(options.sourceDirectory, (error, stats) => error || !stats.isDirectory ? reject(error || 'NotDirectoryError') : resolve()); });
52
52
  await fs.copy(options.sourceDirectory, tmpDir);
53
53
  let zipArchivePath = path.join(tmpDir, options.zipFileName);
@@ -67,7 +67,7 @@ AwsArchitect.prototype.publishZipArchive = async function(options = {}) {
67
67
 
68
68
  AwsArchitect.prototype.publishLambdaArtifactPromise = AwsArchitect.prototype.PublishLambdaArtifactPromise = async function(options = {}) {
69
69
  let lambdaZip = options && options.zipFileName || 'lambda.zip';
70
- let tmpDir = path.join(os.tmpdir(), `lambda-${uuid.v4()}`);
70
+ let tmpDir = path.join(os.tmpdir(), `lambda-${shortUuid.generate()}`);
71
71
 
72
72
  await new Promise((resolve, reject) => {
73
73
  fs.stat(this.SourceDirectory, (error, stats) => {
@@ -41,6 +41,9 @@ class BucketManager {
41
41
  let cacheControl = matchingCacheMap && matchingCacheMap.value || cacheControlRegexMap[relativePathUnixFormat] || cacheControlRegexMap.default || 600;
42
42
  const fileUrl = this.unixify(path.join(version, relativePath));
43
43
  const fileData = await fs.readFile(file);
44
+
45
+ await this.ensureBucketExists(this.Bucket);
46
+
44
47
  const putObjectParams = {
45
48
  Bucket: this.Bucket,
46
49
  Key: fileUrl,
@@ -112,18 +115,21 @@ class BucketManager {
112
115
  await this.S3Manager.putObject(params).promise();
113
116
  }
114
117
 
115
- DeployLambdaPromise(bucket, localPath, remotePath) {
116
- return this.S3Manager.upload({
117
- Bucket: bucket || this.Bucket,
118
- Key: this.unixify(remotePath),
119
- Body: fs.createReadStream(localPath),
120
- ContentType: contentTypeMappingConst[path.extname(remotePath)] || lookup(remotePath) || contentTypeMappingConst.default || 'text/plain',
121
- CacheControl: 'public, max-age=10'
122
- }).promise()
123
- .then(() => { console.log(`====> ${remotePath}`); })
124
- .catch(failure => {
118
+ async DeployLambdaPromise(bucket, localPath, remotePath) {
119
+ await this.ensureBucketExists(bucket || this.Bucket);
120
+
121
+ try {
122
+ await this.S3Manager.upload({
123
+ Bucket: bucket || this.Bucket,
124
+ Key: this.unixify(remotePath),
125
+ Body: fs.createReadStream(localPath),
126
+ ContentType: contentTypeMappingConst[path.extname(remotePath)] || lookup(remotePath) || contentTypeMappingConst.default || 'text/plain',
127
+ CacheControl: 'public, max-age=10'
128
+ }).promise();
129
+ console.log(`====> ${remotePath}`);
130
+ } catch (failure) {
125
131
  throw { File: localPath, Detail: failure };
126
- });
132
+ }
127
133
  }
128
134
 
129
135
  CopyBucket(source, target) {
@@ -153,6 +159,21 @@ class BucketManager {
153
159
  });
154
160
  }
155
161
 
162
+ async ensureBucketExists(bucket) {
163
+ try {
164
+ await this.S3Manager.headBucket({ Bucket: bucket }).promise();
165
+ } catch (error) {
166
+ if (error.code !== 'NotFound') {
167
+ throw error;
168
+ }
169
+
170
+ await this.S3Manager.createBucket({ Bucket: bucket, ObjectOwnership: 'BucketOwnerEnforced', CreateBucketConfiguration: { LocationConstraint: this.S3Manager.config.region } }).promise();
171
+ await this.S3Manager.putPublicAccessBlock({
172
+ Bucket: bucket, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true }
173
+ }).promise();
174
+ }
175
+ }
176
+
156
177
  // ensures a path will be in unix format (that is, forward slash), also on Windows systems.
157
178
  unixify(fullPath) {
158
179
  return fullPath.replace(/\\/g, '/');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-architect",
3
- "version": "6.6.28",
3
+ "version": "6.6.32",
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",
@@ -18,7 +18,7 @@
18
18
  "aws-architect": "./bin/aws-architect.js"
19
19
  },
20
20
  "dependencies": {
21
- "archiver": "^3.1.1",
21
+ "archiver": "^5.3.0",
22
22
  "axios": "0.21",
23
23
  "body-parser": "^1.18.2",
24
24
  "commander": "^2.5.0",
@@ -31,8 +31,8 @@
31
31
  "lodash.isequal": "^4.5.0",
32
32
  "mime-types": "^2.1.27",
33
33
  "morgan": "^1.9.1",
34
- "tmp": "^0.0.33",
35
- "uuid": "^2.0.2"
34
+ "short-uuid": "^4.2.0",
35
+ "tmp": "^0.0.33"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "aws-sdk": ">=2.877.0"