-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsticker-award-service-stack.ts
More file actions
114 lines (101 loc) · 3.64 KB
/
Copy pathsticker-award-service-stack.ts
File metadata and controls
114 lines (101 loc) · 3.64 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2025-Present Datadog, Inc.
*/
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
import { SharedResources } from "../../../../shared/lib/shared-constructs/lib/shared-resources";
import {
DatabaseCredentials,
ConnectionStringFormat,
} from "../../../../shared/lib/shared-constructs/lib/database-credentials";
import { Api } from "./api";
import { Cluster } from "aws-cdk-lib/aws-ecs";
import { StringParameter } from "aws-cdk-lib/aws-ssm";
import { SharedProps } from "../../../../shared/lib/shared-constructs/lib/shared-props";
import {
AWSMessagingProps,
KafkaMessagingProps,
ServiceProps,
} from "./service-props";
export enum MessagingType {
AWS,
KAFKA,
}
export class StickerAwardServiceStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const serviceName = "sticker-award";
const environment = process.env.ENV || "dev";
const messagingType: MessagingType = MessagingType.AWS;
const sharedResources = new SharedResources(this, "SharedResources", {
networkName: `${serviceName}-${environment}-vpc`,
environment: environment,
});
const ddSite = process.env.DD_SITE || "datadoghq.com";
const ddApiKey = process.env.DD_API_KEY || "";
const ddApiKeyParam = new StringParameter(this, "DDApiKeyParam", {
parameterName: `/stickerlandia/${environment}/sticker-award/dd-api-key`,
stringValue: ddApiKey,
simpleName: false,
});
const cluster = new Cluster(this, "ApiCluster", {
vpc: sharedResources.vpc,
clusterName: `${serviceName}-${environment}`,
});
cluster.enableFargateCapacityProviders();
const sharedProps = new SharedProps(
this,
"awards",
serviceName,
cluster,
ddApiKey,
ddApiKeyParam,
ddSite,
true,
{
DD_APM_IGNORE_RESOURCES:
"(GET|HEAD) .*/health$",
}
);
// Create formatted database credentials from the shared RDS secret
const dbCredentials = new DatabaseCredentials(this, "DatabaseCredentials", {
databaseSecretArn: sharedResources.sharedDatabaseSecretArn,
sharedProps: sharedProps,
format: ConnectionStringFormat.POSTGRES_URL,
databaseName: "stickerlandia_awards",
vpc: sharedResources.vpc,
});
const serviceProps: ServiceProps = {
cloudfrontDistribution: sharedResources.cloudfrontDistribution,
domainName: sharedResources.domainName,
connectionStringSecret: dbCredentials.connectionStringSecret!,
databaseCredentials: dbCredentials,
messagingConfiguration: new AWSMessagingProps(
this,
"MessagingProps",
sharedResources,
),
serviceDependencies: [dbCredentials.credentialResource],
};
const api = new Api(this, "Api", {
sharedProps,
serviceProps,
vpc: sharedResources.vpc,
vpcLink: sharedResources.vpcLink,
vpcLinkSecurityGroupId: sharedResources.vpcLinkSecurityGroupId,
httpApi: sharedResources.httpApi,
serviceDiscoveryName: "awards.api",
serviceDiscoveryNamespace: sharedResources.serviceDiscoveryNamespace,
cluster: cluster,
deployInPrivateSubnet: true,
sharedEventBus: sharedResources.sharedEventBus,
});
// CDK Outputs
new cdk.CfnOutput(this, "ServiceApiUrl", {
value: `${sharedResources.domainName}/api/awards/v1`,
description: "Sticker Award Service API URL",
});
}
}