npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-s3-batch

v1.0.2

Published

Serverless plugin to assist with S3 Batch jobs

Downloads

15

Readme

Serverless S3 Batch plugin

The serverless-s3-batch plugin is designed to make it easy to work with S3 Batch operations.

If you're running an S3 Batch operation that invokes a Lambda function, you may be using the Serverless Framework to deploy your function anyway. Using the serverless-s3-batch plugin also assists with:

  • Managing the IAM role for your S3 Batch job

  • Launching your S3 Batch job

For a deep dive and walkthrough on S3 Batch and this plugin, check out this blog post.

Contents:

Installation

Install using Serverless plugin manager

serverless plugin install --name serverless-s3-batch

Install using npm

Install the module using npm:

npm install serverless-s3-batch --save-dev

Add serverless-s3-batch to the plugin list of your serverless.yml file:

plugins:
  - serverless-s3-batch

Quickstart

  1. Configure a function and basic usage of the plugin your serverless.yml:

    service: s3-batch
       
    plugins:
      - serverless-s3-batch
       
    custom:
      s3batch:
        manifest: s3://s3-batch-example/manifest.txt
        report: s3://s3-batch-example/reports
        operation: detectSentiment
       
    provider:
      name: aws
      runtime: python3.7
      stage: dev
      region: us-east-1
       
    functions:
      detectSentiment:
        handler: handler.detect_sentiment
  2. Deploy your service

    $ sls deploy

    This will deploy your function and create the IAM role to be used for your S3 Batch job.

  3. Create your S3 Batch job

    $ sls s3batch create
       
    Serverless: S3 Batch Job created. Job Id: 83e47ce1-0440-4b6c-b36b-284071fafe46
    Serverless:
    Serverless: View in browser: https://console.aws.amazon.com/s3/jobs/83e47ce1-0440-4b6c-b36b-284071fafe46

💥

Configuration

All configuration goes in the s3batch property in the custom block.

Example:

# serverless.yml
custom:
  s3batch:
    manifest: ...
    ...

Manifest

Shorthand version:

custom:
  s3batch:
    manifest: s3://s3-batch-example/manifest.txt

Advanced options:

custom:
  s3batch:
    manifest:
      format: csv # "csv" or "inventory". Default is "csv".
      location: s3://s3-batch-example/manifest.txt
      etag: 'ea42026f5e7aaa0addb4f0bb4131d4fb' # Optional. The plugin will fetch the latest ETag if you don't provide it.

Operation

Shorthand version:

custom:
  s3batch:
    operation: myFunc

The function name must match the name of a function in your serverless.yml and the function must be deployed.

Advanced options:

custom:
  s3batch:
    operation: 
      function: myFunc

I'd like to add support for other operations but haven't yet.

Report

Shorthand version:

custom:
  s3batch:
    report: s3://s3-batch-example/reports

Advanced options:

custom:
  s3batch:
    report:
      location: s3://s3-batch-example/reports
      enabled: true # true or false. Defaults to true if a location is provided.
      scope: all # "all" or "failed". Defaults to "all"
      

Role ARN

The plugin creates a role for use with your S3 Batch job.

By default, it creates a role named <service>-<stage>-<region>-s3BatchRole. You can specify your own name if you want:

custom:
  s3batch:
    role:
      name: myS3BatchRoleName

The role configures a policy with the following IAM statement:

{
  "Effect": "Allow",
  "Action": [
    "s3:GetObject",
    "s3:GetObjectVersion",
    "s3:PutObject",
    "lambda:InvokeFunction"
  ],
  "Resource": "*"
}

This will allow your role to read a manifest, invoke a Lambda function for the operation, and write the report at the end.

If you'd like to customize the IAM statement, you may do so with the following:

custom:
  s3batch:
    role:
      iamRoleStatements:
        - Effect: Allow
        - Action:
        		- s3:GetObject
        - Resource: "arn:aws:s3:::my_bucket"

Note that this will entirely replace the default IAM statement, so make sure you have all permissions you need for your job.

To disable IAM creation behavior and bring your own role, provide a Role ARN in the configuration:

custom:
  s3batch:
    role:
      arn: arn:aws:iam::123456789012:role/S3BatchRole

Future improvements:

  • Ability to run any S3 Batch operation, not just Lambda function operation.