API Reference
    Preparing search index...
    • Searches and extracts data using JMESPath

      Envelope being the JMESPath expression to extract the data you're after

      Built-in JMESPath functions include: powertools_json, powertools_base64, powertools_base64_gzip

      Type Parameters

      • T

      Parameters

      Returns T

      import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes';

      type CustomEvent = {
      body: string; // "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}"
      };

      type EventBody = {
      customerId: string;
      };

      export const handler = async (event: CustomEvent): Promise<unknown> => {
      const payload = extractDataFromEnvelope<EventBody>(event, "powertools_json(body)");
      const { customerId } = payload; // now deserialized
      // ...
      };

      We provide built-in envelopes for popular AWS Lambda event sources to easily decode and/or deserialize JSON objects.

      import {
      extractDataFromEnvelope,
      SQS,
      } from '@aws-lambda-powertools/jmespath/envelopes';
      import type { SQSEvent } from 'aws-lambda';

      type MessageBody = {
      customerId: string;
      };

      export const handler = async (event: SQSEvent): Promise<unknown> => {
      const records = extractDataFromEnvelope<Array<MessageBody>>(event, SQS);
      for (const record in records) { // records is now a list containing the deserialized body of each message
      const { customerId } = record;
      }
      };