Skip to content

Commit 109b7bc

Browse files
benfriebebenfriebe
authored and
benfriebe
committed
feat: add serverless silos cdk project
1 parent 3a201ce commit 109b7bc

24 files changed

+1849
-25
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
## Code of Conduct
22
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
33
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
4-
[email protected] with any additional questions or comments.
4+
[email protected] with any additional questions or comments.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ If you discover a potential security issue in this project we ask that you notif
5656

5757
## Licensing
5858

59-
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
59+
See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.

LICENSE

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
MIT No Attribution
2-
31
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
42

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so.
10-
11-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
13-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
15-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17-
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
software and associated documentation files (the "Software"), to deal in the Software
5+
without restriction, including without limitation the rights to use, copy, modify,
6+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
permit persons to whom the Software is furnished to do so.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 131 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,140 @@
1-
## My Project
1+
# Serverless Silos
22

3-
TODO: Fill this README out!
3+
A reference architecture using services such as CDK and Lambda to demonstrate a hands-on approach to implementing Serverless Silos.
44

5-
Be sure to:
5+
This was demonstrated at AWS Summit ANZ 2023: Simplify multi-tenant microservice applications - https://www.youtube.com/watch?v=upfYIB6Rz0o
66

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
97

10-
## Security
118

12-
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
9+
<p align="center">
10+
<img src="/img/architecture.png" />
11+
</p>
12+
13+
> :warning: This artifact deploys a **public API** resource and should be **deleted** when not in use or a form of **authentication should be added** to the API. You are responsible for the costs associated with deploying this project, it is recommended to **destroy the stack when not in use**.
14+
15+
### Solution Overview
16+
17+
#### Infrastructure Deployment
18+
19+
<p align="center">
20+
<img src="/img/template_synth.png" width="500"/>
21+
</p>
22+
23+
CDK is used to define the infrastructure as code and synthesize CloudFormation templates. The templates are then stored in an S3 bucket for deployment.
24+
25+
To deploy the CDK application:
26+
27+
1. Clone this repository
28+
2. Run `cdk bootstrap` to setup CDK toolkit stack
29+
3. Run `cdk deploy` to deploy the stack (assuming you have AWS credentials in your environment)
30+
31+
#### Tenant Control Plane
32+
33+
The tenant control plane manages tenant lifecycle via API Gateway. Lambda functions handle tenant onboarding/offboarding. DynamoDB stores the state of all tenancies and streams changes to trigger provisioning. Step Functions can be used to orchestrate the provisioning of new tenancies based on DynamoDB state.
34+
35+
**Note**: In the example code the Step Function has been replaced with a single deployment lambda. If you have a multi step deployment process you should use a Step Function to orchestrate it.
36+
37+
<p align="center">
38+
<img src="/img/tenant_control_plane.png" width="800"/>
39+
</p>
40+
41+
#### Tenant Deployment
42+
43+
The onboarding Lambda retrieves templates from S3, populates parameters, and calls CloudFormation to deploy tenant resources.
44+
45+
<p align="center">
46+
<img src="/img/tenant_deployment.png" width="800"/>
47+
</p>
48+
49+
An example tenant stack is then deployed with DynamoDB table, Lambda function, and permissions.
50+
51+
To create, update or delete tenants use the endpoints outlined below.
52+
53+
## Deployed Endpoints
54+
55+
#### Fetch Tenants
56+
**HTTP Method**: GET
57+
**Endpoint**: /tenants
58+
**Description**: Retrieves a list of all tenant records from the system.
59+
**Request**: No request body required.
60+
**Response**: An array of tenant objects in JSON format.
61+
62+
```json
63+
[
64+
{
65+
"tenantName": "silo_tenant",
66+
"status": "running",
67+
"tenantId": "12345678-1234-1234-1234-123456789100",
68+
"created": "1600000000.000000000000000000000",
69+
"deploymentType": "silo",
70+
"tenantSafeName": "silo_tenant"
71+
}
72+
...
73+
]
74+
```
75+
76+
77+
#### Create Tenant
78+
79+
**HTTP Method**: POST
80+
**Endpoint**: /onboarding
81+
**Description**: Onboards a new tenant with a specified name and deployment type.
82+
**Request Body**:
83+
84+
85+
```json
86+
{
87+
"tenantName": "string",
88+
"deploymentType": "string"
89+
}
90+
```
91+
92+
93+
#### Delete Tenant
94+
95+
**HTTP Method**: POST
96+
**Endpoint**: /delete
97+
**Description**: Deletes an existing tenant based on the provided tenant information.
98+
**Request Body**:
99+
100+
```json
101+
{
102+
"tenantName": "string",
103+
"tenantId": "string"
104+
}
105+
```
106+
107+
#### Get Tenant Information
108+
109+
**HTTP Method**: POST
110+
**Endpoint**: /tenant-info
111+
**Description**: Retrieves detailed information for a specific tenant CloudFormation deployment using the tenant's ID.
112+
**Request Body**:
113+
114+
```json
115+
[
116+
{
117+
"LogicalResourceId": "LambdaTenantSilo123456",
118+
"PhysicalResourceId": "12345678-1234-1234-1234-123456789100",
119+
"ResourceType": "AWS::Lambda::Function",
120+
"LastUpdatedTimestamp": "2000-01-01 00:00:00.000000+00:00",
121+
"ResourceStatus": "CREATE_COMPLETE",
122+
"DriftInformation": { "StackResourceDriftStatus": "NOT_CHECKED" }
123+
}
124+
]
125+
```
126+
127+
128+
## Useful commands
129+
* `cdk synth` emits the synthesized CloudFormation template
130+
* `cdk deploy` deploy this stack to your default AWS account/region
131+
* `cdk destroy` destroy this stack and remove resources from your AWS account
132+
13133

14134
## License
15135

16-
This library is licensed under the MIT-0 License. See the LICENSE file.
136+
This library is licensed under the [MIT-0](https://github.com/aws/mit-0) license. For more details, please see [LICENSE](LICENSE) file
137+
138+
## Legal disclaimer
17139

140+
Sample code, software libraries, command line tools, proofs of concept, templates, or other related technology are provided as AWS Content or Third-Party Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content or Third-Party Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content or Third-Party Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content or Third-Party Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.

bin/serverless-silos.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env node
2+
3+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
// SPDX-License-Identifier: MIT-0
5+
6+
import 'source-map-support/register';
7+
import * as cdk from 'aws-cdk-lib';
8+
import { ServerlessSilosStack } from '../lib/serverless-silos-stack';
9+
10+
const app = new cdk.App();
11+
new ServerlessSilosStack(app, 'ServerlessSilosStack', {
12+
/* If you don't specify 'env', this stack will be environment-agnostic.
13+
* Account/Region-dependent features and context lookups will not work,
14+
* but a single synthesized template can be deployed anywhere. */
15+
16+
/* Uncomment the next line to specialize this stack for the AWS Account
17+
* and Region that are implied by the current CLI configuration. */
18+
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
19+
20+
/* Uncomment the next line if you know exactly what Account and Region you
21+
* want to deploy the stack to. */
22+
// env: { account: '123456789012', region: 'us-east-1' },
23+
24+
/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
25+
});

cdk.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts bin/serverless-silos.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true
39+
}
40+
}

img/architecture.png

182 KB
Loading

img/template_synth.png

73.4 KB
Loading

img/tenant_control_plane.png

114 KB
Loading

img/tenant_deployment.png

106 KB
Loading

0 commit comments

Comments
 (0)