# Add e-signatures and clickwrap to an AWS Lambda app

> Add e-signatures and clickwrap to an AWS Lambda app: the esigncomply package in a Node.js handler, an HTTP API or function URL, and a DynamoDB table.

Source: https://esigncomply.com/aws-lambda

Platform · AWS Lambda

To add e-signatures and clickwrap to an AWS Lambda app, bundle the `esigncomply` package with a Node.js handler written as an ES module and store the secret key as a function environment variable. The handler creates the session and confirms the record, and a DynamoDB table keeps the receipt. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/aws-lambda)

`npm install esigncomply`

[AWS Lambda quickstart](https://esigncomply.com/docs/quickstart/aws-lambda)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run locally for AWS Lambda before publishing

**Handler**

index.mjs (excerpt)

```js
// Step 4: create the session with the secret key. The browser gets the client token only.
if (method === "POST" && path === "/api/ceremony") {
  const origin = event.headers.origin ?? `https://${event.requestContext.domainName}`;
  const { data: session, error } = await esc.sessions.create(
    {
      profile: process.env.ESIGNCOMPLY_PROFILE_ID,
      signer,
      documents: [
        { document: DOCUMENTS.terms, version: "current" },
        { document: DOCUMENTS.privacy, version: "current" },
      ],
      context: { url: `${origin}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${crypto.randomUUID()}` },
  );
  if (error) return json(502, { error: error.code });

  // Two invocations can run in two execution environments, so what this one pinned goes to DynamoDB.
  await db.send(new PutCommand({ TableName: TABLE, Item: { signer_id: signer.external_id, version_ids: session.documents.map((d) => d.version_id).sort() } }));
  return json(200, { clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
```

**SAM template**

`template.yaml`

```yaml
# template.yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Esign Comply signup clickwrap on AWS Lambda

Parameters:
  EsignComplyApiKey:
    Type: String
    NoEcho: true # the secret key: never printed, never committed
  EsignComplyProfileId:
    Type: String
  EsignComplyTermsId:
    Type: String
  EsignComplyPrivacyId:
    Type: String
  EsignComplyLive:
    Type: String
    Default: "false" # "true" on the production stack only
    AllowedValues: ["true", "false"]

Resources:
  SignupFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Handler: index.handler
      Runtime: nodejs22.x
      Timeout: 15
      Environment:
        Variables:
          ESIGNCOMPLY_API_KEY: !Ref EsignComplyApiKey
          ESIGNCOMPLY_API_URL: "" # empty: the SDK uses the API host of the key's region
          ESIGNCOMPLY_PROFILE_ID: !Ref EsignComplyProfileId
          ESIGNCOMPLY_TERMS_ID: !Ref EsignComplyTermsId
          ESIGNCOMPLY_PRIVACY_ID: !Ref EsignComplyPrivacyId
          ESIGNCOMPLY_LIVE: !Ref EsignComplyLive
          ACCEPTANCES_TABLE: !Ref AcceptancesTable
          DYNAMODB_ENDPOINT: "" # set only for DynamoDB Local
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref AcceptancesTable
      Events:
        Http:
          Type: HttpApi # every path and method, as payload format 2.0

  # What each session pinned, then the record ID and the receipt.
  AcceptancesTable:
    Type: AWS::Serverless::SimpleTable
    Properties:
      PrimaryKey:
        Name: signer_id
        Type: String

Outputs:
  SignupUrl:
    Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/signup"
```

**Confirm**

index.mjs (excerpt)

```js
// Step 6: confirm the record with the secret key before the account exists.
if (method === "POST" && path === "/api/signup/confirm") {
  const text = event.isBase64Encoded ? Buffer.from(event.body ?? "", "base64").toString() : (event.body ?? "{}");
  const { recordId } = JSON.parse(text);
  const { data: record, error } = await esc.records.get(String(recordId));
  const { Item: row } = await db.send(new GetCommand({ TableName: TABLE, Key: { signer_id: signer.external_id }, ConsistentRead: true }));
  const confirmed =
    !error &&
    row !== undefined &&
    SEALED.includes(record.status) &&
    record.livemode === LIVE &&
    record.signer.external_id === signer.external_id &&
    JSON.stringify(record.documents.map((d) => d.version_id).sort()) === JSON.stringify(row.version_ids);
  console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused");
  if (!confirmed) return json(409, { confirmed: false });

  // Only now create the account. The record ID and the receipt stay in your own table.
  await db.send(
    new UpdateCommand({
      TableName: TABLE,
      Key: { signer_id: signer.external_id },
      UpdateExpression: "SET record_id = :id, receipt = :receipt, accepted_at = :at",
      ExpressionAttributeValues: { ":id": record.id, ":receipt": record.receipt, ":at": record.signed_at },
    }),
  );
  return json(200, { confirmed: true, recordId: record.id });
```

Integrate with AWS Lambda

## How do you integrate Esign Comply with AWS Lambda?

On Lambda the server half is one handler. An HTTP API or a function URL sends it each request as an event in payload format 2.0, and it routes on `event.rawPath`. The `esigncomply` package is bundled in the deployment package and imported as an ES module. Two invocations can run in two execution environments, so the pinned versions go to DynamoDB.

Lambda invokes your function in an execution environment, which provides a secure and isolated runtime environment.

Source: [AWS documentation, Lambda execution environment](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html), read on November 24, 2026.

[AWS Lambda quickstart](https://esigncomply.com/docs/quickstart/aws-lambda) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on AWS Lambda

- **Handler** · `index.mjs`
- **SAM template** · `template.yaml`
- **Confirm** · `index.mjs`

Run on 2026-11-26 on the Lambda Node.js 22 runtime image (Node.js 22.23.5, AWS SDK 3.1105.0) with DynamoDB Local, once behind sam local start-api (SAM CLI 1.155.2, with --no-memory-limit on the test machine) and once with function URL events sent to the runtime emulator, with esigncomply 1.0.4 and the conformance check from esigncomply 1.0.4, against the API in test mode. The AWS settings are from AWS's documentation as of 2026-11-24. The stack has not yet been deployed to AWS.

Three steps

## How does Esign Comply fit with AWS Lambda?

Each step uses a feature AWS Lambda already has. The secret key stays on the server side of AWS Lambda in all three.

1. **A function environment variable holds the key**

   The SAM template takes `ESIGNCOMPLY_API_KEY` as a `NoEcho` parameter and passes it to the function. Lambda encrypts environment variables at rest, and the handler reads the key from `process.env`. Source: [AWS documentation, Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html), read on November 24, 2026.

2. **The handler creates the session**

   An HTTP API or a function URL sends `POST /api/ceremony` to the handler as one event. It calls `esc.sessions.create` and returns the client token. The same function serves the signup page, and the browser SDK records the ceremony from the signer's device. Source: [AWS documentation, Invoking Lambda function URLs](https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html), read on November 24, 2026.

3. **A DynamoDB item keeps the receipt**

   The session route stores the pinned versions in a DynamoDB table that the template declares. The confirm route reads the record with the secret key, compares it with the item, and writes the record ID and the receipt into it.

AWS Lambda setup

## Where do the key, the preview hosts and the webhook go on AWS Lambda?

Four settings carry an Esign Comply integration on AWS Lambda. What is said here about AWS Lambda was read from its own documentation, and the quickstart has each command.

### Environment variables

Set them through the template's parameters, with one stack for test and one for production. `aws lambda update-function-configuration --environment` replaces the whole set of variables of a function, so a call that names one removes the others. AWS recommends AWS Secrets Manager over environment variables for API keys.

Source: [AWS documentation, Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html), read on November 24, 2026.

### Local runs and the template

`sam local start-api` runs the function on the Lambda runtime image and serves it over HTTP on port 3000. It takes the function's variables from `--env-vars`, and it passes only the variables the template declares, so declare every one the handler reads.

Source: [AWS documentation, sam local start-api](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html), read on November 24, 2026.

### Test stacks and test mode

An HTTP API answers on `https://<api-id>.execute-api.<region>.amazonaws.com` and a function URL on `https://<url-id>.lambda-url.<region>.on.aws`. A test key refuses a host it does not know: list the exact host of your test stack under Domains in the Esign Comply dashboard as a test origin.

Source: [AWS documentation, Invoking Lambda function URLs](https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html), read on November 24, 2026.

### The registered domain and the webhook

Go live on a domain you own, verified with one DNS record: the file method is offered only for a fixed list of platform suffixes, and it includes neither `amazonaws.com` nor `on.aws`. For the `record.completed` webhook, add a route to the handler and register its production URL under Webhooks in the Esign Comply dashboard.

Read on November 24, 2026: [AWS documentation, Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html), [AWS documentation, Invoking Lambda function URLs](https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html), [AWS documentation, Lambda execution environment](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html), [AWS documentation, Lambda with Node.js](https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html), [AWS documentation, sam local start-api](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html), [AWS documentation, sam deploy](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html).

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a AWS Lambda app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes on AWS Lambda, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap on AWS Lambda

```
Add Esign Comply clickwrap to my app on AWS Lambda: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/aws-lambda.md (the steps and the tested code for AWS Lambda)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

AWS Lambda facts
- Packages (the only ones that exist): esigncomply (server) and @esigncomply/browser. Bundle esigncomply in the deployment package. It is an ES module: write the handler as index.mjs, or set "type": "module". require("esigncomply") fails on the Lambda runtime.
- The handler receives payload format 2.0 events from an HTTP API or a function URL: event.rawPath, event.requestContext.http.method, event.headers, event.body.
- The secret key is the function environment variable ESIGNCOMPLY_API_KEY, passed as a NoEcho parameter of the template. Never commit it. Never print it.
- Two invocations can run in two execution environments. Keep the pinned version IDs in DynamoDB, never in a variable outside the handler.
- sam local start-api passes only the variables the template declares. Declare every variable the handler reads.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Handler, POST /api/ceremony: create the session with esc.sessions.create and an Idempotency-Key, save the signer ID and the pinned version IDs in DynamoDB, and return only clientToken, apiUrl and documents.
4. Handler, GET /legal/terms and /legal/privacy: render the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Handler, POST /api/signup/confirm: read the record with esc.records.get and require: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the item in DynamoDB. Only then create the account, and store the record ID and the receipt in the same item.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:3000/signup --callback http://localhost:3000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures on AWS Lambda?

These are specific to AWS Lambda. Each one was seen while the quickstart's code was run, or is in AWS Lambda's own documentation.

- **require() of the package fails on the Lambda runtime**

  `esigncomply` is an ES module. On the Lambda Node.js 22 runtime image, a CommonJS handler that called `require("esigncomply")` failed with `ERR_REQUIRE_ESM`. Name the handler `index.mjs`, or set `"type": "module"`, and use `import`.

- **State outside the handler belongs to one execution environment**

  Objects declared outside the handler stay initialized while Lambda reuses an environment, and AWS says not to assume it persists. Two invocations can also run in two environments. Keep the pinned versions in DynamoDB and read them with a consistent read, as the quickstart does.

  Source: [AWS documentation, Lambda execution environment](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html), read on November 24, 2026.

- **sam local passes only the variables the template declares**

  In the test run, a variable that was in the `--env-vars` file and not under `Environment` in the template never reached the function, and the handler called the API without it. Declare every variable in the template, even with an empty value.

## Where are the AWS Lambda quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[AWS Lambda quickstart](https://esigncomply.com/docs/quickstart/aws-lambda)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature on AWS Lambda?

The same record on every stack and platform. Your AWS Lambda code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures on AWS Lambda

### How does test mode work on AWS Lambda preview URLs?

Lambda has no preview deployments of its own: a test stack is your preview. Its HTTP API or function URL has a host of its own, which a test key refuses until you list that exact host under Domains as a test origin. On `localhost`, with `sam local start-api`, a test key works with no setup.

### Where should the receipt be stored on AWS Lambda?

In a DynamoDB table, beside the signer ID and the record ID. The confirm route writes both once the record is confirmed. The quickstart declares the table in its SAM template and uses one item for the pinned versions and the receipt.

### Can a Lambda handler import the esigncomply package?

Yes. Every server call of the quickstart was made with the package on the Lambda Node.js 22 runtime image, bundled in the function's folder. It has to be imported from an ES module: a CommonJS handler that called `require` on it failed with `ERR_REQUIRE_ESM`.

### Can I use a function URL instead of an HTTP API?

Yes. AWS documents that function URL events follow the same schema as payload format 2.0 of API Gateway, which is what the handler reads. The quickstart's handler passed the conformance check behind the local HTTP API of SAM and with function URL events sent to the runtime emulator.

### Was this code deployed to AWS?

Not yet. The handler ran on the Lambda Node.js 22 runtime image with DynamoDB Local, and the template passed `sam validate --lint`. The AWS settings come from AWS's documentation as of November 24, 2026. `sam deploy`, the IAM policy and the hosted table are proven only by a deployment.

### Other platforms

- [Vercel](https://esigncomply.com/vercel)
- [Cloudflare Workers](https://esigncomply.com/cloudflare-workers)
- [Netlify](https://esigncomply.com/netlify)

### Stacks used with AWS Lambda

- [Node.js](https://esigncomply.com/nodejs)
- [Express](https://esigncomply.com/express)
- [React](https://esigncomply.com/react)

[All platforms](https://esigncomply.com/platforms) · [All stacks](https://esigncomply.com/stacks) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Run the signing flow in your Lambda function. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/aws-lambda)

Free plan: 10 live signatures a month and a full test mode. No card required.

AWS Lambda is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about AWS Lambda is from AWS Lambda's documentation or from a test run, as marked, on November 24, 2026. `/aws-lambda.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
