Class ResourceControllerAbstract

An abstract class to inherit to manage API requests (AWS API Gateway) in an AWS Lambda function.

Hierarchy (view full)

Constructors

Properties

auth0User: Auth0User
authorization: string
body: any
callback: Callback
claims: any
clientBundle: string = null
clientPlatform: string = '?'
clientVersion: string = '?'
cognitoUser: CognitoUser
currentLang: string
defaultLang: string
event: APIGatewayProxyEventV2 | APIGatewayProxyEvent
httpMethod: string
initError: boolean = false
logRequestsWithKey: string
logger: LambdaLogger = ...
metrics: CloudWatchMetrics
path: string
pathParameters: any
principalId: string
project: string = PROJECT
queryParams: any
resource: string = RESOURCE
resourceId: string
resourcePath: string
returnStatusCode?: number
stage: string = STAGE
templateMatcher: RegExp = ...
tracer: Tracer
tracerLambdaSegment: any
tracerRCSegment: any
translations: any

Methods

  • Whether the current request comes from an internal API request, i.e. it was invoked by another controller.

    Returns boolean

    don't run a Lambda from another Lambda (bad practice)

  • Parameters

    • limitBodyArrayDisplay: boolean = false

    Returns Record<string, any>

  • Get the current log level for the current Lambda function's logger. Note: "FATAL" means that no log will be printed.

    Returns
        | "TRACE"
        | "DEBUG"
        | "INFO"
        | "WARN"
        | "ERROR"
        | "FATAL"

  • Force the parsing of a query parameter as an array of strings.

    Parameters

    • paramName: string

    Returns string[]

  • Force the parsing of a query parameter as a boolean.

    Parameters

    • paramName: string

    Returns boolean

  • Simulate an internal API request, invoking directly the lambda and therefore saving resources.

    Parameters

    Returns Promise<any>

    the body of the response

    don't run a Lambda from another Lambda (bad practice)

  • Load a shared resource in the back-end (translation, template, etc.). Search for the specified file path in both the Lambda function's main folder and the layers folder.

    Parameters

    • filePath: string

    Returns string

  • Load the translations from the shared resources and set them with a fallback language.

    Parameters

    • lang: string
    • OptionaldefLang: string

    Returns void

  • Publish the CloudWatch metrics (default and custom-defined) at the end of a reqeust.

    Parameters

    • statusCode: number
    • Optionalerror: any

    Returns void

  • Set the log level for the current Lambda function's logger.

    Parameters

    • logLevel:
          | "TRACE"
          | "DEBUG"
          | "INFO"
          | "WARN"
          | "ERROR"
          | "FATAL"

    Returns void

  • Check whether shared resource exists in the back-end (translation, template, etc.). Search for the specified file path in both the Lambda function's main folder and the layers folder.

    Parameters

    • filePath: string

    Returns boolean

  • Store the log associated to the request (no response/error handling).

    Parameters

    • succeeded: boolean

    Returns Promise<void>

  • Get a translated term by key, optionally interpolating variables (e.g. {{user}}). If the term doesn't exist in the current language, it is searched in the default language.

    Parameters

    • key: string
    • OptionalinterpolateParams: any

    Returns string