Repository navigation
Expand file tree
/
Copy pathstack.ts
More file actions
60 lines (49 loc) · 1.95 KB
/
Copy pathstack.ts
File metadata and controls
60 lines (49 loc) · 1.95 KB
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
import { CfnOutput, Stack, StackProps } from 'aws-cdk-lib'
import { FunctionUrlAuthType } from 'aws-cdk-lib/aws-lambda'
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'
import { Construct } from 'constructs'
import { resolve } from 'node:path'
import { IEventStore } from '../../../src/aws-cdk'
import { commonFunctionEnv, commonFunctionProps } from '../../lib/cdk-defaults'
export interface CounterStackProps extends StackProps {
eventStore: IEventStore
}
export class CounterStack extends Stack {
constructor(scope: Construct, id: string, { eventStore, ...props }: CounterStackProps) {
super(scope, id, props)
// -------------------------------------------
// Aggregate
const command = new NodejsFunction(this, 'counter-basic-command-handler', {
functionName: 'counter-basic-command-handler',
...commonFunctionProps,
entry: resolve(import.meta.dirname, 'command.ts'),
environment: {
...commonFunctionEnv,
eventStoreConfig: eventStore.config
}
})
eventStore.grantReadWriteEvents(command)
const commandUrl = command.addFunctionUrl({
authType: FunctionUrlAuthType.NONE,
})
// -------------------------------------------
// Query
const query = new NodejsFunction(this, 'counter-basic-query-handler', {
functionName: 'counter-basic-query-handler',
...commonFunctionProps,
entry: resolve(import.meta.dirname, 'query.ts'),
environment: {
...commonFunctionEnv,
eventStoreConfig: eventStore.config
}
})
eventStore.grantReadEvents(query)
const queryUrl = query.addFunctionUrl({
authType: FunctionUrlAuthType.NONE,
})
new CfnOutput(this, 'commandUrl', { value: commandUrl.url })
new CfnOutput(this, 'queryUrl', { value: queryUrl.url })
new CfnOutput(this, 'commandLogGroup', { value: command.logGroup.logGroupName })
new CfnOutput(this, 'queryLogGroup', { value: query.logGroup.logGroupName })
}
}