aws-architect 6.7.112 → 6.7.115
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/bin/template/package.json +0 -1
- package/index.js +251 -244
- package/package.json +1 -2
package/index.js
CHANGED
|
@@ -14,289 +14,296 @@ let BucketManager = require('./lib/BucketManager');
|
|
|
14
14
|
let CloudFormationDeployer = require('./lib/CloudFormationDeployer');
|
|
15
15
|
let LockFinder = require('./lib/lockFinder');
|
|
16
16
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.SourceDirectory = (apiOptions || {}).sourceDirectory;
|
|
22
|
-
|
|
23
|
-
if (!aws.config.region && apiOptions.regions && apiOptions.regions[0]) {
|
|
24
|
-
aws.config.update({ region: apiOptions.regions[0] });
|
|
25
|
-
}
|
|
26
|
-
this.Configuration = new ApiConfiguration(apiOptions, 'index.js', aws.config.region || 'us-east-1');
|
|
17
|
+
async function GetAccountIdPromise() {
|
|
18
|
+
const callerData = await new aws.STS().getCallerIdentity().promise();
|
|
19
|
+
return callerData.Account;
|
|
20
|
+
}
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
function getStageName(stage) {
|
|
23
|
+
return stage.replace(/[^a-zA-Z0-9-]/g, '-');
|
|
24
|
+
}
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
class AwsArchitect {
|
|
27
|
+
constructor(packageMetadata, apiOptions, contentOptions) {
|
|
28
|
+
this.PackageMetadata = packageMetadata || {};
|
|
29
|
+
this.ContentOptions = contentOptions || {};
|
|
30
|
+
this.deploymentBucket = (apiOptions || {}).deploymentBucket;
|
|
31
|
+
this.SourceDirectory = (apiOptions || {}).sourceDirectory;
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
if (!aws.config.region && apiOptions.regions && apiOptions.regions[0]) {
|
|
34
|
+
aws.config.update({ region: apiOptions.regions[0] });
|
|
35
|
+
}
|
|
36
|
+
this.Configuration = new ApiConfiguration(apiOptions, 'index.js', aws.config.region || 'us-east-1');
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
38
|
+
if (this.Configuration.Regions.length === 0) { throw new Error('A single region must be defined in the apiOptions.'); }
|
|
39
|
+
if (this.Configuration.Regions.length > 1) { throw new Error('Only deployments to a single region are allowed at this time.'); }
|
|
40
|
+
this.Region = this.Configuration.Regions[0];
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
const callerData = await new aws.STS().getCallerIdentity().promise();
|
|
43
|
-
return callerData.Account;
|
|
44
|
-
}
|
|
42
|
+
this.ApiGatewayManager = new ApiGatewayManager(this.PackageMetadata.name, this.PackageMetadata.version, this.Region);
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
this.LambdaManager = new LambdaManager(this.Region);
|
|
45
|
+
|
|
46
|
+
let s3Factory = new aws.S3({ region: this.Region });
|
|
47
|
+
this.BucketManager = new BucketManager(s3Factory, this.ContentOptions.bucket);
|
|
48
|
+
this.CloudFormationDeployer = new CloudFormationDeployer(this.Region, this.BucketManager, this.deploymentBucket);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
let
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
AwsArchitect.prototype.publishLambdaArtifactPromise = AwsArchitect.prototype.PublishLambdaArtifactPromise = async function(options = {}) {
|
|
69
|
-
let lambdaZip = options && options.zipFileName || 'lambda.zip';
|
|
70
|
-
let tmpDir = path.join(os.tmpdir(), `lambda-${shortUuid.generate()}`);
|
|
71
|
-
|
|
72
|
-
await new Promise((resolve, reject) => {
|
|
73
|
-
fs.stat(this.SourceDirectory, (error, stats) => {
|
|
74
|
-
if (error) { return reject({ Error: `Path does not exist: ${this.SourceDirectory} - ${error}` }); }
|
|
75
|
-
if (!stats.isDirectory) { return reject({ Error: `Path is not a directory: ${this.SourceDirectory}` }); }
|
|
76
|
-
return resolve(null);
|
|
50
|
+
|
|
51
|
+
async publishZipArchive(options = {}) {
|
|
52
|
+
if (!options.zipFileName || !this.deploymentBucket || !options.sourceDirectory) {
|
|
53
|
+
throw Error('The zipFileName, sourceDirectory, api options deploymentBucket must be specified.');
|
|
54
|
+
}
|
|
55
|
+
let tmpDir = path.join(os.tmpdir(), `zipDirectory-${shortUuid.generate()}`);
|
|
56
|
+
await new Promise((resolve, reject) => { fs.stat(options.sourceDirectory, (error, stats) => error || !stats.isDirectory ? reject(error || 'NotDirectoryError') : resolve()); });
|
|
57
|
+
await fs.copy(options.sourceDirectory, tmpDir);
|
|
58
|
+
let zipArchivePath = path.join(tmpDir, options.zipFileName);
|
|
59
|
+
await new Promise((resolve, reject) => {
|
|
60
|
+
let zipStream = fs.createWriteStream(zipArchivePath);
|
|
61
|
+
zipStream.on('close', () => resolve());
|
|
62
|
+
|
|
63
|
+
let archive = archiver.create('zip', {});
|
|
64
|
+
archive.on('error', e => reject({ Error: e }));
|
|
65
|
+
archive.pipe(zipStream);
|
|
66
|
+
archive.glob('**', { dot: true, cwd: tmpDir, ignore: options.zipFileName });
|
|
67
|
+
archive.finalize();
|
|
77
68
|
});
|
|
78
|
-
});
|
|
79
69
|
|
|
80
|
-
|
|
70
|
+
await this.BucketManager.DeployLambdaPromise(this.deploymentBucket, zipArchivePath, `${this.PackageMetadata.name}/${this.PackageMetadata.version}/${options.zipFileName}`);
|
|
71
|
+
}
|
|
81
72
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (lockFile.file) {
|
|
86
|
-
await fs.copy(lockFile.file, path.join(tmpDir, path.basename(lockFile.file)));
|
|
87
|
-
}
|
|
73
|
+
async publishLambdaArtifactPromise(options = {}) {
|
|
74
|
+
let lambdaZip = options && options.zipFileName || 'lambda.zip';
|
|
75
|
+
let tmpDir = path.join(os.tmpdir(), `lambda-${shortUuid.generate()}`);
|
|
88
76
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
fs.stat(this.SourceDirectory, (error, stats) => {
|
|
79
|
+
if (error) { return reject({ Error: `Path does not exist: ${this.SourceDirectory} - ${error}` }); }
|
|
80
|
+
if (!stats.isDirectory) { return reject({ Error: `Path is not a directory: ${this.SourceDirectory}` }); }
|
|
81
|
+
return resolve(null);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await fs.copy(this.SourceDirectory, tmpDir);
|
|
86
|
+
|
|
87
|
+
// (default: true) If set to true, will attempt to copy and install packages related to deployment (i.e. package.json for node)
|
|
88
|
+
if (options.autoHandleCompileOfSourceDirectory !== false) {
|
|
89
|
+
const lockFile = await new LockFinder().findLockFile(this.SourceDirectory);
|
|
90
|
+
if (lockFile.file) {
|
|
91
|
+
await fs.copy(lockFile.file, path.join(tmpDir, path.basename(lockFile.file)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
await fs.writeJson(path.join(tmpDir, 'package.json'), this.PackageMetadata);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw { Error: 'Failed writing production package.json file.', Details: error };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let cmd = lockFile.command;
|
|
101
|
+
await new Promise((resolve, reject) => {
|
|
102
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
103
|
+
exec(cmd, { cwd: tmpDir }, (error, stdout, stderr) => {
|
|
104
|
+
if (error) { return reject({ Error: 'Failed installing production npm modules.', Details: error }); }
|
|
105
|
+
return resolve(tmpDir);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
93
108
|
}
|
|
94
109
|
|
|
95
|
-
let
|
|
110
|
+
let zipArchivePath = path.join(tmpDir, lambdaZip);
|
|
96
111
|
await new Promise((resolve, reject) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
112
|
+
let zipStream = fs.createWriteStream(zipArchivePath);
|
|
113
|
+
zipStream.on('close', () => resolve({ Archive: zipArchivePath }));
|
|
114
|
+
|
|
115
|
+
let archive = archiver.create('zip', {});
|
|
116
|
+
archive.on('error', e => reject({ Error: e }));
|
|
117
|
+
archive.pipe(zipStream);
|
|
118
|
+
archive.glob('**', { dot: true, cwd: tmpDir, ignore: lambdaZip });
|
|
119
|
+
archive.finalize();
|
|
102
120
|
});
|
|
121
|
+
|
|
122
|
+
let bucket = options && options.bucket || this.deploymentBucket;
|
|
123
|
+
if (bucket) {
|
|
124
|
+
await this.BucketManager.DeployLambdaPromise(bucket, zipArchivePath, `${this.PackageMetadata.name}/${this.PackageMetadata.version}/${lambdaZip}`);
|
|
125
|
+
}
|
|
103
126
|
}
|
|
104
127
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
zipStream.on('close', () => resolve({ Archive: zipArchivePath }));
|
|
109
|
-
|
|
110
|
-
let archive = archiver.create('zip', {});
|
|
111
|
-
archive.on('error', e => reject({ Error: e }));
|
|
112
|
-
archive.pipe(zipStream);
|
|
113
|
-
archive.glob('**', { dot: true, cwd: tmpDir, ignore: lambdaZip });
|
|
114
|
-
archive.finalize();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
let bucket = options && options.bucket || this.deploymentBucket;
|
|
118
|
-
if (bucket) {
|
|
119
|
-
await this.BucketManager.DeployLambdaPromise(bucket, zipArchivePath, `${this.PackageMetadata.name}/${this.PackageMetadata.version}/${lambdaZip}`);
|
|
128
|
+
async validateTemplate(stackTemplate, stackConfiguration) {
|
|
129
|
+
const result = await this.CloudFormationDeployer.validateTemplate(stackTemplate, stackConfiguration && stackConfiguration.stackName, `${this.PackageMetadata.name}/${this.PackageMetadata.version}`);
|
|
130
|
+
return result;
|
|
120
131
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
AwsArchitect.prototype.deployTemplate = AwsArchitect.prototype.DeployTemplate = function(stackTemplate, stackConfiguration, parameters) {
|
|
128
|
-
return this.CloudFormationDeployer.deployTemplate(stackTemplate, stackConfiguration, parameters, `${this.PackageMetadata.name}/${this.PackageMetadata.version}`);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
AwsArchitect.prototype.deployStackSetTemplate = async function(stackTemplate, stackConfiguration, parameters) {
|
|
132
|
-
try {
|
|
133
|
-
await new aws.IAM().getRole({ RoleName: 'AWSCloudFormationStackSetExecutionRole' }).promise();
|
|
134
|
-
} catch (error) {
|
|
135
|
-
if (error.code === 'NoSuchEntity') {
|
|
136
|
-
throw { title: 'Role "AWSCloudFormationStackSetExecutionRole" must exist. See prerequisite for cloudformation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html' };
|
|
137
|
-
}
|
|
138
|
-
throw error;
|
|
132
|
+
|
|
133
|
+
async deployTemplate(stackTemplate, stackConfiguration, parameters) {
|
|
134
|
+
const result = await this.CloudFormationDeployer.deployTemplate(stackTemplate, stackConfiguration, parameters, `${this.PackageMetadata.name}/${this.PackageMetadata.version}`);
|
|
135
|
+
return result;
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
138
|
+
async deployStackSetTemplate(stackTemplate, stackConfiguration, parameters) {
|
|
139
|
+
try {
|
|
140
|
+
await new aws.IAM().getRole({ RoleName: 'AWSCloudFormationStackSetExecutionRole' }).promise();
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error.code === 'NoSuchEntity') {
|
|
143
|
+
throw { title: 'Role "AWSCloudFormationStackSetExecutionRole" must exist. See prerequisite for cloudformation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html' };
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
await new aws.IAM().getRole({ RoleName: 'AWSCloudFormationStackSetAdministrationRole' }).promise();
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (error.code === 'NoSuchEntity') {
|
|
152
|
+
throw { title: 'Role "AWSCloudFormationStackSetAdministrationRole" must exist. See prerequisite for cloudformation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html' };
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let accountId = await GetAccountIdPromise();
|
|
158
|
+
return this.CloudFormationDeployer.deployStackSetTemplate(accountId, stackTemplate, stackConfiguration, parameters, `${this.PackageMetadata.name}/${this.PackageMetadata.version}`);
|
|
148
159
|
}
|
|
149
160
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
};
|
|
161
|
+
async configureStackSetForAwsOrganization(stackTemplate, stackConfiguration, parameters) {
|
|
162
|
+
try {
|
|
163
|
+
await new aws.IAM().getRole({ RoleName: 'AWSCloudFormationStackSetExecutionRole' }).promise();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error.code === 'NoSuchEntity') {
|
|
166
|
+
throw { title: 'Role "AWSCloudFormationStackSetExecutionRole" must exist. See prerequisite for cloudformation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html' };
|
|
167
|
+
}
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
153
170
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
171
|
+
try {
|
|
172
|
+
await new aws.IAM().getRole({ RoleName: 'AWSCloudFormationStackSetAdministrationRole' }).promise();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error.code === 'NoSuchEntity') {
|
|
175
|
+
throw { title: 'Role "AWSCloudFormationStackSetAdministrationRole" must exist. See prerequisite for cloudformation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs-self-managed.html' };
|
|
176
|
+
}
|
|
177
|
+
throw error;
|
|
160
178
|
}
|
|
161
|
-
|
|
179
|
+
|
|
180
|
+
return this.CloudFormationDeployer.configureStackSetForAwsOrganization(stackTemplate, stackConfiguration, parameters);
|
|
162
181
|
}
|
|
163
182
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
183
|
+
async deployStagePromise(stage, lambdaVersion) {
|
|
184
|
+
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
185
|
+
if (!lambdaVersion) { throw new Error('Deployment lambdaVersion is not defined.'); }
|
|
186
|
+
const restApi = await this.ApiGatewayManager.GetApiGatewayPromise();
|
|
187
|
+
const result = await this.ApiGatewayManager.DeployStagePromise(restApi, stage, lambdaVersion);
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async removeStagePromise(stage, functionName) {
|
|
192
|
+
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
193
|
+
let stageName = getStageName(stage);
|
|
194
|
+
const apiGateway = await this.ApiGatewayManager.GetApiGatewayPromise();
|
|
195
|
+
const result = await this.ApiGatewayManager.RemoveStagePromise(apiGateway, stageName);
|
|
196
|
+
if (functionName) {
|
|
197
|
+
await this.LambdaManager.removeVersion(functionName, stageName);
|
|
169
198
|
}
|
|
170
|
-
|
|
199
|
+
return { title: 'Successfully deleted stage', stage: stageName, details: result };
|
|
171
200
|
}
|
|
172
201
|
|
|
173
|
-
|
|
174
|
-
|
|
202
|
+
async deployLambdaFunctionVersion(options = {}) {
|
|
203
|
+
let stage = options.stage;
|
|
204
|
+
let stageName = getStageName(stage);
|
|
205
|
+
let functionName = options.functionName;
|
|
206
|
+
let bucket = options.deploymentBucketName || this.deploymentBucket;
|
|
207
|
+
let deploymentKey = options.deploymentKeyName;
|
|
208
|
+
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
175
209
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
210
|
+
try {
|
|
211
|
+
const lambda = await this.LambdaManager.PublishNewVersion(functionName, bucket, deploymentKey);
|
|
212
|
+
const lambdaArn = lambda.FunctionArn;
|
|
213
|
+
const lambdaVersion = lambda.Version;
|
|
214
|
+
await this.LambdaManager.SetAlias(functionName, stageName, lambdaVersion);
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
LambdaResult: {
|
|
218
|
+
LambdaFunctionArn: lambdaArn,
|
|
219
|
+
LambdaVersion: lambdaVersion
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
} catch (failure) {
|
|
223
|
+
throw { Error: 'Failed to create and deploy updates.', Details: failure };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
182
226
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
227
|
+
async publishAndDeployStagePromise(options = {}) {
|
|
228
|
+
let stage = options.stage;
|
|
229
|
+
let stageName = getStageName(stage);
|
|
230
|
+
let functionName = options.functionName;
|
|
231
|
+
let bucket = options.deploymentBucketName || this.deploymentBucket;
|
|
232
|
+
let deploymentKey = options.deploymentKeyName;
|
|
233
|
+
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
186
234
|
|
|
187
|
-
AwsArchitect.prototype.removeStagePromise = AwsArchitect.prototype.RemoveStagePromise = async function(stage, functionName) {
|
|
188
|
-
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
189
|
-
let stageName = getStageName(stage);
|
|
190
|
-
const apiGateway = await this.ApiGatewayManager.GetApiGatewayPromise();
|
|
191
|
-
const result = await this.ApiGatewayManager.RemoveStagePromise(apiGateway, stageName);
|
|
192
|
-
if (functionName) {
|
|
193
|
-
await this.LambdaManager.removeVersion(functionName, stageName);
|
|
194
|
-
}
|
|
195
|
-
return { title: 'Successfully deleted stage', stage: stageName, details: result };
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
AwsArchitect.prototype.deployLambdaFunctionVersion = async function(options = {}) {
|
|
199
|
-
let stage = options.stage;
|
|
200
|
-
let stageName = getStageName(stage);
|
|
201
|
-
let functionName = options.functionName;
|
|
202
|
-
let bucket = options.deploymentBucketName || this.deploymentBucket;
|
|
203
|
-
let deploymentKey = options.deploymentKeyName;
|
|
204
|
-
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
const lambda = await this.LambdaManager.PublishNewVersion(functionName, bucket, deploymentKey);
|
|
208
|
-
const lambdaArn = lambda.FunctionArn;
|
|
209
|
-
const lambdaVersion = lambda.Version;
|
|
210
|
-
await this.LambdaManager.SetAlias(functionName, stageName, lambdaVersion);
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
LambdaResult: {
|
|
214
|
-
LambdaFunctionArn: lambdaArn,
|
|
215
|
-
LambdaVersion: lambdaVersion
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
} catch (failure) {
|
|
219
|
-
throw { Error: 'Failed to create and deploy updates.', Details: failure };
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
AwsArchitect.prototype.publishAndDeployStagePromise = AwsArchitect.prototype.PublishAndDeployStagePromise = async function(options = {}) {
|
|
224
|
-
let stage = options.stage;
|
|
225
|
-
let stageName = getStageName(stage);
|
|
226
|
-
let functionName = options.functionName;
|
|
227
|
-
let bucket = options.deploymentBucketName || this.deploymentBucket;
|
|
228
|
-
let deploymentKey = options.deploymentKeyName;
|
|
229
|
-
if (!stage) { throw new Error('Deployment stage is not defined.'); }
|
|
230
|
-
|
|
231
|
-
try {
|
|
232
|
-
const lambda = await this.LambdaManager.PublishNewVersion(functionName, bucket, deploymentKey);
|
|
233
|
-
const lambdaArn = lambda.FunctionArn;
|
|
234
|
-
const lambdaVersion = lambda.Version;
|
|
235
|
-
await this.LambdaManager.SetAlias(functionName, stageName, lambdaVersion);
|
|
236
|
-
|
|
237
|
-
let apiGateway;
|
|
238
235
|
try {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
236
|
+
const lambda = await this.LambdaManager.PublishNewVersion(functionName, bucket, deploymentKey);
|
|
237
|
+
const lambdaArn = lambda.FunctionArn;
|
|
238
|
+
const lambdaVersion = lambda.Version;
|
|
239
|
+
await this.LambdaManager.SetAlias(functionName, stageName, lambdaVersion);
|
|
240
|
+
|
|
241
|
+
let apiGateway;
|
|
242
|
+
try {
|
|
243
|
+
apiGateway = await this.ApiGatewayManager.GetApiGatewayPromise();
|
|
244
|
+
} catch (error) {
|
|
245
|
+
if (error.code === 'ApiGatewayServiceNotFound') {
|
|
246
|
+
return {
|
|
247
|
+
LambdaResult: {
|
|
248
|
+
LambdaFunctionArn: lambdaArn,
|
|
249
|
+
LambdaVersion: lambdaVersion
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
throw error;
|
|
248
254
|
}
|
|
249
|
-
|
|
255
|
+
|
|
256
|
+
let accountId = await GetAccountIdPromise();
|
|
257
|
+
await this.LambdaManager.SetPermissionsPromise(accountId, lambdaArn, apiGateway.Id, this.Region, stageName);
|
|
258
|
+
const data = await this.ApiGatewayManager.DeployStagePromise(apiGateway, stageName, stage, lambdaVersion);
|
|
259
|
+
return {
|
|
260
|
+
LambdaResult: {
|
|
261
|
+
LambdaFunctionArn: lambdaArn,
|
|
262
|
+
LambdaVersion: lambdaVersion
|
|
263
|
+
},
|
|
264
|
+
ApiGatewayResult: data,
|
|
265
|
+
ServiceApi: `https://${apiGateway.Id}.execute-api.${this.Region}.amazonaws.com/${stageName}`
|
|
266
|
+
};
|
|
267
|
+
} catch (failure) {
|
|
268
|
+
throw { Error: 'Failed to create and deploy updates.', Details: failure };
|
|
250
269
|
}
|
|
270
|
+
}
|
|
251
271
|
|
|
252
|
-
|
|
253
|
-
await this.LambdaManager.
|
|
254
|
-
const data = await this.ApiGatewayManager.DeployStagePromise(apiGateway, stageName, stage, lambdaVersion);
|
|
255
|
-
return {
|
|
256
|
-
LambdaResult: {
|
|
257
|
-
LambdaFunctionArn: lambdaArn,
|
|
258
|
-
LambdaVersion: lambdaVersion
|
|
259
|
-
},
|
|
260
|
-
ApiGatewayResult: data,
|
|
261
|
-
ServiceApi: `https://${apiGateway.Id}.execute-api.${this.Region}.amazonaws.com/${stageName}`
|
|
262
|
-
};
|
|
263
|
-
} catch (failure) {
|
|
264
|
-
throw { Error: 'Failed to create and deploy updates.', Details: failure };
|
|
272
|
+
async cleanupPreviousFunctionVersions(functionName, forceRemovalOfAliases) {
|
|
273
|
+
await this.LambdaManager.cleanupProduction(functionName, forceRemovalOfAliases, false);
|
|
265
274
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
275
|
+
|
|
276
|
+
async publishWebsite(version, options = {}) {
|
|
277
|
+
if (!this.BucketManager.Bucket) { throw new Error('Bucket in content options has not been defined.'); }
|
|
278
|
+
if (!this.ContentOptions.contentDirectory) { throw new Error('Content directory is not defined.'); }
|
|
279
|
+
|
|
280
|
+
const result = await this.BucketManager.Deploy(this.ContentOptions.contentDirectory, version, options.cacheControlRegexMap || [], options.contentTypeMappingOverride);
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async deleteWebsiteVersion(version) {
|
|
285
|
+
if (!this.BucketManager.Bucket) { throw new Error('Bucket in content options has not been defined.'); }
|
|
286
|
+
if (!version) { throw new Error('Website version is required.'); }
|
|
287
|
+
|
|
288
|
+
const result = await this.BucketManager.deletePath(version);
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async run(port, logger) {
|
|
293
|
+
try {
|
|
294
|
+
let indexPath = path.join(this.SourceDirectory, 'index.js');
|
|
295
|
+
let api = require(indexPath);
|
|
296
|
+
let server = new Server(this.ContentOptions.contentDirectory, api, logger);
|
|
297
|
+
let attemptPort = port || 8080;
|
|
298
|
+
let resolvedPort = await server.Run(attemptPort);
|
|
299
|
+
if (resolvedPort !== attemptPort) {
|
|
300
|
+
console.log('Requested Port is in use. Using the next available port.');
|
|
301
|
+
}
|
|
302
|
+
return Promise.resolve({ title: `Server started successfully at 'http://localhost:${resolvedPort}', lambda routes available at /api, /triggers/event, /triggers/schedule.`, server });
|
|
303
|
+
} catch (exception) {
|
|
304
|
+
return Promise.reject({ title: 'Failed to start server', error: exception.stack || exception });
|
|
295
305
|
}
|
|
296
|
-
return Promise.resolve({ title: `Server started successfully at 'http://localhost:${resolvedPort}', lambda routes available at /api, /triggers/event, /triggers/schedule.`, server });
|
|
297
|
-
} catch (exception) {
|
|
298
|
-
return Promise.reject({ title: 'Failed to start server', error: exception.stack || exception });
|
|
299
306
|
}
|
|
300
|
-
}
|
|
307
|
+
}
|
|
301
308
|
|
|
302
309
|
module.exports = AwsArchitect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-architect",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.115",
|
|
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,7 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"archiver": "^5.3.0",
|
|
22
|
-
"axios": "0.28",
|
|
23
22
|
"body-parser": "^1.18.2",
|
|
24
23
|
"commander": "^2.5.0",
|
|
25
24
|
"cookie-parser": "^1.4.7",
|