constructor()

in src/patterns/api-lambda.ts [63:89]


  constructor(scope: GuStack, id: string, props: GuApiLambdaProps) {
    super(scope, id, {
      ...props,
    });

    // 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 resourceToInvoke = this.alias ?? this;

    this.api = new LambdaRestApi(this, props.api.id, {
      handler: resourceToInvoke,

      // Override to avoid clashes as default is just api ID, which is often shared across stages.
      restApiName: `${scope.stack}-${scope.stage}-${props.api.id}`,

      ...props.api,
    });

    if (!props.monitoringConfiguration.noMonitoring) {
      new GuApiGateway5xxPercentageAlarm(scope, {
        app: props.app,
        apiGatewayInstance: this.api,
        snsTopicName: props.monitoringConfiguration.snsTopicName,
        ...props.monitoringConfiguration.http5xxAlarm,
      });
    }
  }