| 37 | import { ParamDashboardStack } from './param-dashboard-stack'; |
| 38 | |
| 39 | /** |
| 40 | * APIStack |
| 41 | * Sets up the API Gateway and Lambda functions for the parameterization service. |
| 42 | * The API Gateway is responsible for creating REST endpoints, each of which is integrated with a Lambda function. |
| 43 | */ |
| 44 | export class APIStack extends cdk.Stack { |
| 45 | public readonly url: CfnOutput; |
| 46 | |
| 47 | constructor( |
| 48 | parent: Construct, |
| 49 | name: string, |
| 50 | props: cdk.StackProps & { |
| 51 | provisionedConcurrency: number; |
| 52 | internalApiKey?: string; |
| 53 | throttlingOverride?: string; |
| 54 | chatbotSNSArn?: string; |
| 55 | stage: string; |
| 56 | envVars: Record<string, string>; |
| 57 | hardQuoteCosignerBackendAccounts?: readonly string[]; |
| 58 | // Backend accounts that may reach the market-maker egress proxy. Absent (local stack) |
| 59 | // means no proxy is created. |
| 60 | egressProxyBackendAccounts?: readonly string[]; |
| 61 | // Backend accounts that may write analytics records cross-account. Absent (local stack) |
| 62 | // means no direct-write streams or writer role are created. |
| 63 | analyticsWriterBackendAccounts?: readonly string[]; |
| 64 | // Backend accounts that may read the circuit-breaker bench state and roster, and record posted |
| 65 | // orders and filler addresses, during the ramp. Absent (local stack) means no role is created. |
| 66 | rampAccessBackendAccounts?: readonly string[]; |
| 67 | // Share (0-100) of the quote Lambdas' market-maker webhook calls sent through the egress |
| 68 | // proxy. Needs the proxy. Absent leaves the Lambdas untouched. |
| 69 | egressProxyWebhookSharePercent?: number; |
| 70 | } |
| 71 | ) { |
| 72 | super(parent, name, props); |
| 73 | const region = cdk.Stack.of(this).region; |
| 74 | const { provisionedConcurrency, internalApiKey, stage, chatbotSNSArn } = props; |
| 75 | |
| 76 | // The quote analytics streams exist only where the analytics writer does (AnalyticsStack). Their |
| 77 | // names are fixed per stage, so the Lambdas get names and a grant without referencing the |
| 78 | // nested stack. |
| 79 | const directStreams = props.analyticsWriterBackendAccounts?.length |
| 80 | ? quoteAnalyticsDirectStreamNames(stage) |
| 81 | : undefined; |
| 82 | const softQuoteAnalyticsEnv = directStreams && { |
| 83 | [QUOTE_ANALYTICS_STREAM_ENV.QuoteRequest]: directStreams.rfqRequest, |
| 84 | [QUOTE_ANALYTICS_STREAM_ENV.QuoteResponse]: directStreams.rfqResponse, |
| 85 | }; |
| 86 | const hardQuoteAnalyticsEnv = directStreams && { |
| 87 | [QUOTE_ANALYTICS_STREAM_ENV.HardRequest]: directStreams.hardRequest, |
| 88 | [QUOTE_ANALYTICS_STREAM_ENV.HardResponse]: directStreams.hardResponse, |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * API Gateway Initialization |
| 93 | */ |
| 94 | const accessLogGroup = new aws_logs.LogGroup(this, `${SERVICE_NAME}APIGAccessLogs`); |
| 95 | |
| 96 | const api = new aws_apigateway.RestApi(this, `${SERVICE_NAME}`, { |
nothing calls this directly
no outgoing calls
no test coverage detected