-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
66 lines (55 loc) 路 1.52 KB
/
index.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
//
// Copyright (C) 2020 SSH Communications Security Corp.
//
// This file may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
// https://github.com/SSHcom/c3
//
import * as cdk from '@aws-cdk/core'
import * as iam from '@aws-cdk/aws-iam'
import * as ddb from '@aws-cdk/aws-dynamodb'
import * as logs from '@aws-cdk/aws-logs'
import * as c3 from '@ssh/c3'
//
// Usage
// cdk deploy c3-example-kms
// cdk deploy c3-example
//
const app = new cdk.App()
const env = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
}
//
// Intentional split of essential app resources from other's
const stackKey = new cdk.Stack(app, 'c3-example-kms', { env })
const key = new c3.kms.SymmetricKey(stackKey, 'MyKey', {
alias: 'my-encryption-key'
})
key.grantToService(new iam.ServicePrincipal(`logs.${cdk.Aws.REGION}.amazonaws.com`))
//
//
const stack = new cdk.Stack(app, 'c3-example', { env })
const removalPolicy = cdk.RemovalPolicy.DESTROY
const kmsKey = c3.kms.fromAlias(stack, key.alias.aliasName)
new c3.logs.LogGroup(stack, 'MyLogs', {
kmsKey,
logGroupName: 'MyLogs',
removalPolicy,
retention: logs.RetentionDays.ONE_DAY,
})
new c3.dynamodb.Table(stack, 'MyDynamo', {
kmsKey,
tableName: 'MyDynamo',
partitionKey: {type: ddb.AttributeType.STRING, name: 'id'},
})
new c3.s3.Bucket(stack, 'MyBucket', {
kmsKey,
removalPolicy,
})
new c3.secretsmanager.Secret(stack, 'MySecret', {
kmsKey,
secretName: 'MySecret',
removalPolicy,
})
app.synth()