in src/patterns/api-multiple-lambdas.ts [133:159]
constructor(scope: GuStack, props: GuApiGatewayWithLambdaByPathProps) {
super(scope, props.app); // The assumption is `app` is unique
const apiGateway = new RestApi(scope, "RestApi", {
// Override to avoid clashes as default is just api ID, which is often shared across stages.
restApiName: `${scope.stack}-${scope.stage}-${props.app}`,
...props,
});
this.api = apiGateway;
props.targets.map((target) => {
const resource = apiGateway.root.resourceForPath(target.path);
// If we have an alias, use this to ensure that all requests are routed to a published Lambda version.
// Otherwise, use the latest unpublished version ($LATEST)
const lambdaTarget = target.lambda.alias ?? target.lambda;
resource.addMethod(target.httpMethod, new LambdaIntegration(lambdaTarget), {
apiKeyRequired: target.apiKeyRequired,
});
});
if (!isNoMonitoring(props.monitoringConfiguration)) {
new GuApiGateway5xxPercentageAlarm(scope, {
app: props.app,
apiGatewayInstance: apiGateway,
snsTopicName: props.monitoringConfiguration.snsTopicName,
...props.monitoringConfiguration.http5xxAlarm,
});
}
}