-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverless.js
48 lines (37 loc) · 1.11 KB
/
serverless.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const { Component } = require('@serverless/core');
const Cloudmap = require('./cloudmap');
const region = process.env.AWS_REGION;
class CloudmapComponent extends Component {
async default(inputs = {}) {
const { namespace, service } = inputs;
this.state.namespace = namespace;
this.state.service = service;
await this.save();
this.context.status('Creating namespace');
await Cloudmap.createNamespace({
name: namespace,
});
this.context.status('Create service');
const { id } = await Cloudmap.createService({
name: service,
namespace,
});
const resources = Object.keys(inputs.resources).map((key) => {
return {
...inputs.resources[key],
name: key,
};
});
this.context.status('Registering instances');
await Promise.all(resources.map(async (instance) => {
return Cloudmap.createInstance(instance, id);
}));
}
async remove() {
this.context.status('Deleting service');
const { service } = this.state;
await Cloudmap.deleteService(service);
}
}
module.exports = CloudmapComponent;