1.0.0 • Published 1 year ago

medusa-plugin-aws-storage v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

medusa-plugin-aws-storage

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

Options

OptionDescriptionRequiredExample
regionAWS regionYesus-east-1
access_key_idAWS Access Key IDYes
secret_access_keyAWS Secret Access KeyYes
s3_bucketS3 bucket name. This can be omitted if cloud_front_distribution_id is provided and CloudFront distribution has an S3 origin.Conditionally
s3_origin_pathS3 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_optionsS3 upload options{}
s3_upload_options.ACLS3 ACLpublic-read
s3_upload_options.CacheControlS3 Cache Controlmax-age=31536000
s3_upload_options.ServerSideEncryptionS3 Server Side EncryptionAES256
s3_upload_options.StorageClassS3 Storage ClassSTANDARD
cloud_front_distribution_idCloudFront Distribution ID. Required if s3_bucket is not provided. CloudFront distribution must have an S3 origin.Conditionally
cloud_front_cache_behavior_path_patternCloudFront 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_idCloudFront Key Pair ID. Required if cloud_front_distribution_id is provided and signed URLs will be used.Conditionally
cloud_front_key_private_keyCloudFront Key Private Key. Required if cloud_front_distribution_id is provided and signed URLs will be used.Conditionally
domain_nameDomain 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_durationThe number of seconds before the signed URL expires3600
use_httpsWhether to use http or httpstrue

Usage

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

{
  "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 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.