All Projects → ar90n → Serverless S3 Local

ar90n / Serverless S3 Local

Licence: mit
Serverless s3 local plugin.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Serverless S3 Local

Serverless Cljs Plugin
Serverless plugin for Clojurescript deployment w/ cljs-lambda
Stars: ✭ 72 (-44.19%)
Mutual labels:  serverless, serverless-plugin
Neardb
Simple document db made for infinitely scalable globally distributed reads.
Stars: ✭ 92 (-28.68%)
Mutual labels:  serverless, s3
Serverless Plugin Git Variables
⚡️ Expose git variables to serverless
Stars: ✭ 75 (-41.86%)
Mutual labels:  serverless, serverless-plugin
Aws Testing Library
Chai (https://chaijs.com) and Jest (https://jestjs.io/) assertions for testing services built with aws
Stars: ✭ 52 (-59.69%)
Mutual labels:  serverless, s3
Serverless Layers
Serverless.js plugin that implements AWS Lambda Layers which reduces drastically lambda size, warm-up and deployment time.
Stars: ✭ 119 (-7.75%)
Mutual labels:  serverless, serverless-plugin
Serverless Reqvalidator Plugin
Serverless plugin to attach AWS API Gateway Basic Request Validation https://rafpe.ninja/2017/12/18/serverless-own-plugin-to-attach-aws-api-gateway-basic-request-validation/
Stars: ✭ 59 (-54.26%)
Mutual labels:  serverless, serverless-plugin
Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+7570.54%)
Mutual labels:  serverless, s3
Plugins
Serverless Plugins – Extend the Serverless Framework with these community driven plugins –
Stars: ✭ 850 (+558.91%)
Mutual labels:  serverless, serverless-plugin
Serverless Plugins
Collection of serverless plugins ⚡️
Stars: ✭ 126 (-2.33%)
Mutual labels:  serverless, serverless-plugin
Serverless Webpack
Serverless plugin to bundle your lambdas with Webpack
Stars: ✭ 1,595 (+1136.43%)
Mutual labels:  serverless, serverless-plugin
Serverless Export Env
Serverless plugin to export environment variables into a .env file
Stars: ✭ 51 (-60.47%)
Mutual labels:  serverless, serverless-plugin
Serverless Architectures Aws
The code repository for the Serverless Architectures on AWS book
Stars: ✭ 120 (-6.98%)
Mutual labels:  serverless, s3
Serverless Es Logs
A Serverless plugin to transport logs to ElasticSearch
Stars: ✭ 51 (-60.47%)
Mutual labels:  serverless, serverless-plugin
Cloud Volume
Read and write Neuroglancer datasets programmatically.
Stars: ✭ 63 (-51.16%)
Mutual labels:  serverless, s3
Workshop Donkeytracker
Workshop to build a serverless tracking application for your mobile device with an AWS backend
Stars: ✭ 27 (-79.07%)
Mutual labels:  serverless, s3
Historical
A serverless, event-driven AWS configuration collection service with configuration versioning.
Stars: ✭ 85 (-34.11%)
Mutual labels:  serverless, s3
Serverless Dynalite
Serverless plugin to run Dynalite locally (No JVM needed!) to handle DynamoDB development. Can watch for table config changes.
Stars: ✭ 19 (-85.27%)
Mutual labels:  serverless, serverless-plugin
Serverless Python Requirements
⚡️🐍📦 Serverless plugin to bundle Python packages
Stars: ✭ 838 (+549.61%)
Mutual labels:  serverless, serverless-plugin
S3 To Lambda Patterns
Example applications for the S3-to-Lambda patterns series in the AWS Compute Blog and learning path. Questions? @jbesw.
Stars: ✭ 95 (-26.36%)
Mutual labels:  serverless, s3
Website
⚡️ Instantly deploy static website on serverless infrastructure with zero configuration using Serverless Components.
Stars: ✭ 118 (-8.53%)
Mutual labels:  serverless, s3

serverless-s3-local

serverless npm version MIT licensed npm downloads dependencies dev-dependencies

serverless-s3-local is a Serverless plugin to run S3 clone in local. This is aimed to accelerate development of AWS Lambda functions by local testing. I think it is good to collaborate with serverless-offline.

Installation

Use npm

npm install serverless-s3-local --save-dev

Use serverless plugin install

sls plugin install --name serverless-s3-local

Example

serverless.yaml

service: serverless-s3-local-example
provider:
  name: aws
  runtime: nodejs12.x
plugins:
  - serverless-s3-local
  - serverless-offline
custom:
# Uncomment only if you want to collaborate with serverless-plugin-additional-stacks
# additionalStacks:
#    permanent:
#      Resources:
#        S3BucketData:
#            Type: AWS::S3::Bucket
#            Properties:
#                BucketName: ${self:service}-data
  s3:
    host: localhost
    directory: /tmp
resources:
  Resources:
    NewResource:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: local-bucket
functions:
  webhook:
    handler: handler.webhook
    events:
      - http:
        method: GET
        path: /
  s3hook:
    handler: handler.s3hook
    events:
      - s3: local-bucket
        event: s3:*

handler.js

const AWS = require('aws-sdk');

module.exports.webhook = (event, context, callback) => {
  const S3 = new AWS.S3({
    s3ForcePathStyle: true,
    accessKeyId: 'S3RVER', // This specific key is required when working offline
    secretAccessKey: 'S3RVER',
    endpoint: new AWS.Endpoint('http://localhost:4569'),
  });
  S3.putObject({
    Bucket: 'local-bucket',
    Key: '1234',
    Body: new Buffer('abcd')
  }, () => {} );
};

module.exports.s3hook = (event, context) => {
  console.log(JSON.stringify(event));
  console.log(JSON.stringify(context));
  console.log(JSON.stringify(process.env));
};

Configuration options

Configuration options can be defined in multiple ways. They will be parsed with the following priority:

  • custom.s3 in serverless.yml
  • custom.serverless-offline in serverless.yml
  • Default values (see table below)
Option Description Type Default value
address The host/IP to bind the S3 server to string 'localhost'
host The host where internal S3 calls are made. Should be the same as address string
port The port that S3 server will listen to number 4569
directory The location where the S3 files will be created. The directory must exist, it won't be created string './buckets'
accessKeyId The Access Key Id to authenticate requests string 'S3RVER'
secretAccessKey The Secret Access Key to authenticate requests string 'S3RVER'
cors The S3 CORS configuration XML. See AWS docs string | Buffer
website The S3 Website configuration XML. See AWS docs string | Buffer
noStart Set to true if you already have an S3rver instance running boolean false
allowMismatchedSignatures Prevent SignatureDoesNotMatch errors for all well-formed signatures boolean false
silent Suppress S3rver log messages boolean false
serviceEndpoint Override the AWS service root for subdomain-style access string amazonaws.com
httpsProtocol To enable HTTPS, specify directory (relative to your cwd, typically your project dir) for both cert.pem and key.pem files. string
vhostBuckets Disable vhost-style access for all buckets boolean true

Feature

  • Start local S3 server with specified root directory and port.
  • Create buckets at launching.
  • Support serverless-plugin-additional-stacks
  • Support serverless-webpack
  • Support serverless-plugin-existing-s3
  • Support S3 events.

Working with IaC tools

If your want to work with IaC tools such as terraform, you have to manage creating bucket process. In this case, please follow the below steps.

  1. Comment out configurations about S3 Bucket from resources section in serverless.yml.
#resources:
#  Resources:
#    NewResource:
#      Type: AWS::S3::Bucket
#      Properties:
#        BucketName: local-bucket
  1. Create bucket directory in s3rver working directory.
$ mkdir /tmp/local-bucket

Triggering AWS Events offline

This plugin will create a temporary directory to store mock S3 info. You must use the AWS cli to trigger events locally. First, using aws configure set up a new profile, i.e. aws configure --profile s3local. The default creds are

aws_access_key_id = S3RVER
aws_secret_access_key = S3RVER

You can now use this profile to trigger events. e.g. to trigger a put-object on a file at ~/tmp/userdata.csv in a local bucket run: aws --endpoint http://localhost:4569 s3 cp ~/tmp/data.csv s3://local-bucket/userdata.csv --profile s3local

You should see the event trigger in the serverless offline console: info: PUT /local-bucket/user-data.csv 200 16ms 0b and a new object with metadata will appear in your local bucket.

See also

License

This software is released under the MIT License, see LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].