# medusa-plugin-aws-storage

> Medusa plugin for AWS storage

Latest version **1.0.0** (published 2023-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install medusa-plugin-aws-storage
pnpm add medusa-plugin-aws-storage
yarn add medusa-plugin-aws-storage
bun add medusa-plugin-aws-storage
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-02-27 |
| First published | 2023-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 39.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Luis Paredes |
| Maintainers | lparedesl |
| Keywords | ecommerce, medusa, medusa-plugin-storage, aws, file, storage, s3, cloudfront, cdn |

## Links

- npm: https://www.npmjs.com/package/medusa-plugin-aws-storage
- npm.io page: https://npm.io/package/medusa-plugin-aws-storage

## Dependencies (4)

- [@aws-sdk/client-s3](https://npm.io/package/@aws-sdk/client-s3.md) ^3.279.0
- [@aws-sdk/client-cloudfront](https://npm.io/package/@aws-sdk/client-cloudfront.md) ^3.279.0
- [@aws-sdk/cloudfront-signer](https://npm.io/package/@aws-sdk/cloudfront-signer.md) ^3.272.0
- [@aws-sdk/s3-request-presigner](https://npm.io/package/@aws-sdk/s3-request-presigner.md) ^3.279.0

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-02-27
- 0.3.3 — 2023-02-26
- 0.3.2 — 2023-02-26
- 0.3.1 — 2023-02-26
- 0.3.0 — 2023-02-26
- 0.2.0 — 2023-02-26
- 0.1.0 — 2023-02-26

## README

# medusa-plugin-aws-storage

Upload files to an AWS S3 bucket. Optionally serve files through CloudFront.

## Options

| Option                                  | Description                                                                                                                                                                                                                                                                                               | Required      | Example            |
|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|--------------------|
| region                                  | AWS region                                                                                                                                                                                                                                                                                                | Yes           | `us-east-1`        |
| access_key_id                           | AWS Access Key ID                                                                                                                                                                                                                                                                                         | Yes           |                    |
| secret_access_key                       | AWS Secret Access Key                                                                                                                                                                                                                                                                                     | Yes           |                    |
| s3_bucket                               | S3 bucket name. This can be omitted if `cloud_front_distribution_id` is provided and CloudFront distribution has an S3 origin.                                                                                                                                                                            | Conditionally |                    |
| s3_origin_path                          | S3 origin. If `cloud_front_distribution_id` is provided then origin path has to be part of the distribution's S3 origins. If `cloud_front_distribution_id` is provided and `s3_origin_path` is not provided, then the distribution's default cache behavior's origin path will be used. Defaults to `''`. |               | `/assets`          |
| s3_upload_options                       | S3 upload options                                                                                                                                                                                                                                                                                         |               | `{}`               |
| s3_upload_options.ACL                   | S3 ACL                                                                                                                                                                                                                                                                                                    |               | `public-read`      |
| s3_upload_options.CacheControl          | S3 Cache Control                                                                                                                                                                                                                                                                                          |               | `max-age=31536000` |
| s3_upload_options.ServerSideEncryption  | S3 Server Side Encryption                                                                                                                                                                                                                                                                                 |               | `AES256`           |
| s3_upload_options.StorageClass          | S3 Storage Class                                                                                                                                                                                                                                                                                          |               | `STANDARD`         |
| cloud_front_distribution_id             | CloudFront Distribution ID. Required if `s3_bucket` is not provided. CloudFront distribution must have an S3 origin.                                                                                                                                                                                      | Conditionally |                    |
| cloud_front_cache_behavior_path_pattern | CloudFront Cache Behavior Path Pattern. Used when other than default cache behavior needs to be used. If not provided, then the default cache behavior will be used. Ignored when `cloud_front_distribution_id` is not provided.                                                                          |               | `images/*`         |
| cloud_front_key_pair_id                 | CloudFront Key Pair ID. Required if `cloud_front_distribution_id` is provided and signed URLs will be used.                                                                                                                                                                                               | Conditionally |                    |
| cloud_front_key_private_key             | CloudFront Key Private Key. Required if `cloud_front_distribution_id` is provided and signed URLs will be used.                                                                                                                                                                                           | Conditionally |                    |
| domain_name                             | Domain name. If `cloud_front_distribution_id` is provided then domain name has to be part of the distribution's aliases. If `cloud_front_distribution_id` is provided and `domain_name` is not provided, then the 1st distribution alias will be used. Defaults to S3 Bucket URL.                         |               | `my-domain.com`    |
| download_url_duration                   | The number of seconds before the signed URL expires                                                                                                                                                                                                                                                       |               | `3600`             |
| use_https                               | Whether to use `http` or `https`                                                                                                                                                                                                                                                                          |               | `true`             |

## Usage

```js
const plugins = [
  // ...
  {
    resolve: `medusa-plugin-aws-storage`,
    options: {
      region: process.env.S3_REGION,
      access_key_id: process.env.S3_ACCESS_KEY_ID,
      secret_access_key: process.env.S3_SECRET_ACCESS_KEY,
      s3_bucket: process.env.S3_BUCKET,
    },
  },
]
```

## S3 Bucket Policy

```json
{
  "Version": "2012-10-17",
  "Id": "Policy1397632521960",
  "Statement": [
    {
      "Sid": "Stmt1397633323327",
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::<YOUR_BUCKET_NAME>/*"
    }
  ]
}
```

## User Permissions

Your user must have the `AmazonS3FullAccess` policy attached to it. You can refer to [this guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-and-attach-iam-policy.html) to learn how to add a policy if necessary.

If using CloudFront, your user must have the `CloudFrontFullAccess` policy attached to it.

## CloudFront Signed URLs

Please note the process for creating a signed URL with Cloudfront is very different from the process for S3. For more information, please visit the documentation for [restricting CloudFront content with signed URLs and signed cookies](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html).

---
_Source: https://npm.io/package/medusa-plugin-aws-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
