forked from aws-samples/bedrock-claude-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-publish.ts
73 lines (65 loc) · 2.42 KB
/
api-publish.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
#!/usr/bin/env node
import "source-map-support/register";
import * as cdk from "aws-cdk-lib";
import { ApiPublishmentStack } from "../lib/api-publishment-stack";
import * as apigateway from "aws-cdk-lib/aws-apigateway";
import { resolveApiPublishParameters } from "../lib/utils/parameter-models";
const app = new cdk.App();
// Get parameters specific to API publishing
const params = resolveApiPublishParameters();
const sepHyphen = params.envPrefix ? "-" : "";
// Parse allowed origins
const publishedApiAllowedOrigins = JSON.parse(
params.publishedApiAllowedOrigins || '["*"]'
);
// Log all parameters at once for debugging
console.log("API Publish Parameters:", JSON.stringify(params));
const webAclArn = cdk.Fn.importValue(
`${params.envPrefix}${sepHyphen}PublishedApiWebAclArn`
);
const conversationTableName = cdk.Fn.importValue(
`${params.envPrefix}${sepHyphen}BedrockClaudeChatConversationTableName`
);
const tableAccessRoleArn = cdk.Fn.importValue(
`${params.envPrefix}${sepHyphen}BedrockClaudeChatTableAccessRoleArn`
);
const largeMessageBucketName = cdk.Fn.importValue(
`${params.envPrefix}${sepHyphen}BedrockClaudeChatLargeMessageBucketName`
);
// NOTE: DO NOT change the stack id naming rule.
new ApiPublishmentStack(app, `ApiPublishmentStack${params.publishedApiId}`, {
env: {
region: process.env.CDK_DEFAULT_REGION,
},
bedrockRegion: params.bedrockRegion,
conversationTableName: conversationTableName,
tableAccessRoleArn: tableAccessRoleArn,
webAclArn: webAclArn,
largeMessageBucketName: largeMessageBucketName,
usagePlan: {
throttle:
params.publishedApiThrottleRateLimit !== undefined &&
params.publishedApiThrottleBurstLimit !== undefined
? {
rateLimit: params.publishedApiThrottleRateLimit,
burstLimit: params.publishedApiThrottleBurstLimit,
}
: undefined,
quota:
params.publishedApiQuotaLimit !== undefined &&
params.publishedApiQuotaPeriod !== undefined
? {
limit: params.publishedApiQuotaLimit,
period: apigateway.Period[params.publishedApiQuotaPeriod],
}
: undefined,
},
deploymentStage: params.publishedApiDeploymentStage,
corsOptions: {
allowOrigins: publishedApiAllowedOrigins,
allowMethods: apigateway.Cors.ALL_METHODS,
allowHeaders: apigateway.Cors.DEFAULT_HEADERS,
allowCredentials: true,
},
});
cdk.Tags.of(app).add("CDKEnvironment", params.envName);