-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
97 lines (83 loc) · 3.2 KB
/
app.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Stack } from 'aws-cdk-lib';
import { Stage, StageProps } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { CreatePost } from './components/create-post';
import { Data } from './components/data';
import { GetPost } from './components/get-post';
import { Network } from './components/network';
import { Api } from './constructs/api';
import { Monitoring } from './constructs/monitoring';
/**
* My main application stage this contains all of the stack/resources
* for my application and can be deployed as a single unit
*/
export class AppStage extends Stage {
/**
* The public facing Http API
*/
public readonly api: Api;
/**
* The stack containing the application
*/
public readonly appStack: Stack;
/**
* The stack containing the monitoring resources
*/
public readonly monitoringStack: Stack;
/**
* This contains the route urls that is supported by the API
* this allows for accessing the needed URL with autocomplete
*/
public readonly routes: {
'GET /posts': (postId: string) => string;
'POST /posts': string;
};
constructor(scope: Construct, id: string, props?: StageProps) {
super(scope, id, props);
// -------------------------------------------------------------------
// ---------------------Monitoring Stack------------------------------
// -------------------------------------------------------------------
// This is separate from the other stacks to avoid circular dependencies
const monitoringStack = new Stack(this, 'MonitoringStack');
const monitor = new Monitoring(monitoringStack, 'Monitoring');
// -------------------------------------------------------------------
// -------------------------Data Stack-------------------------------
// -------------------------------------------------------------------
// Stack containing my stateful resources. Enabled extra protection
const datastore = new Stack(this, 'DataStack', {
terminationProtection: true,
});
const table = new Data(datastore, 'PostsTable', { monitor });
// -----------------------------------------------------------
// --------------------App Stack------------------------------
// -----------------------------------------------------------
// Contains resources for my application. This includes the VPC, but could also
// not include the VPC
const appStack = new Stack(this, 'AppStack');
const network = new Network(appStack, 'Network', {});
// ------------Create Rest API-------------------
const api = new Api(appStack, 'Api', { monitor, vpc: network.cluster.vpc });
// ---------------------Create an ECS Service-----------------------
new GetPost(appStack, 'GetPost', {
api,
cluster: network.cluster,
monitor,
table,
});
// -------------------Create a Lambda Service-----------------------
new CreatePost(appStack, 'CreatePost', {
api,
monitor,
table,
});
this.api = api;
this.appStack = appStack;
this.monitoringStack = monitoringStack;
this.routes = {
['GET /posts']: (path: string) => {
return `${api.url!}/post/${path}`;
},
['POST /posts']: `${api.url!}/post`,
};
}
}