Socket
Book a DemoInstallSign in
Socket

middy-store-s3

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy-store-s3

Amazon S3 Store for middy-store

latest
Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
495
57.64%
Maintainers
1
Weekly downloads
 
Created
Source

Amazon S3 Store middy-store-s3

This package provides a Store implementation for middy-store that uses Amazon S3 to store and load payloads. It uses the @aws-sdk/client-s3 to interact with Amazon S3.

Prerequisites

This package middy-store-s3 and its docs only cover the Amazons S3 Store. Please read the docs for middy-store for more information on how to use the middy-store package.

Install

npm install middy-store middy-store-s3

Usage

import { middyStore } from 'middy-store';
import { S3Store } from 'middy-store-s3';

const handler = middy()
  .use(
    middyStore({
      stores: [
        new S3Store({
          config: { region: "us-east-1" },
          bucket: "bucket",
          key: ({ payload }) => randomUUID(),
          format: "arn",
        }),
      ],
    }),
  )
  .handler(async (input) => {
    return {
      random: randomBytes(1024 * 1024).toString("hex"),
    };
  });

Options

The S3Store accepts the following options:

OptionTypeDefaultDescription
bucketstring | Fn<string>RequiredThe name of the S3 bucket to store the payloads.
keystring | Fn<string>randomUUIDThe key to store the payload in the bucket. Defaults to randomUUID() from node:crypto.
configS3ClientConfig | Fn<S3ClientConfig>{}The S3 client configuration.
formatS3ReferenceFormaturl-s3-global-pathThe format of the S3 reference: arn, object or one of the URL formats from amazon-s3-url package. Defaults to S3 URI format s3://<bucket>/<...keys>.
maxSizenumberundefinedThe maximum payload size in bytes that can be stored in S3. If the payload exceeds this size, it will not be stored in S3.
loggerLoggerundefinedThe logger function to use for logging.

IAM Permissions

The S3 Store requires specific IAM permissions to function properly. The required permissions depend on the features you use:

Basic Operations

For storing and loading payloads, the following permissions are required:

  • s3:PutObject - Required to store payloads in the S3 bucket
  • s3:GetObject - Required to load payloads from the S3 bucket

If you enable the deleteAfterLoad option in loadingOptions, you also need:

  • s3:DeleteObject - Required to delete payloads after they have been loaded

Example IAM Policy

Note: Replace your-bucket-name with the actual name of your S3 bucket. If you use multiple buckets, include all bucket ARNs in the Resource array.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::your-bucket-name/*"
    }
  ]
}

FAQs

Package last updated on 26 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts