New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lambda-s3-mv

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-s3-mv

This nodejs module will move files to another S3 location.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-77.78%
Maintainers
1
Weekly downloads
 
Created
Source

lambda-s3-mv

npm install lambda-s3-mv --save

Introduction

This nodejs module will move S3 files to another S3 location.

Description

The AWS S3 sdk doesn't come out with a built-in move files operation. This module will handle that for you using the available built-in operations, such copyObject (and deleteObjects if "createCopy" set to false).

This module can move single S3 file, or can move all the files in the specified S3 sourcePath parameter.

/*
 * This nodejs module will move files to another S3 location. It has also an option to just copy the files.
 * @param {options} - parameters, as follows
    {
        sourceBucket: 's3-source-bucket-name',
        sourcePath: 's3-source-prefix-path',
        sourceFiles: ['source-file1.txt', 'source-file2.txt'],
        targetBucket: 's3-target-bucket-name',
        targetPath: 's3-target-prefix-path',
        targetFiles: ['source-file1-moved.txt', 'source-file2-moved.txt'],
        createCopy: false
    }
 * @return {object} - a JSON object containing the details of the files that has been moved or copied.
    {
        s3Bucket: 's3-target-bucket-name',
        s3Objects: [
            '/s3-target-prefix-path/source-file1.txt', 
            '/s3-target-prefix-path/source-file2.txt'
        ]
    }
 */
OptionsRequiredDescription
sourceBucketREQUIREDthe bucket name containing the source files
sourcePathREQUIREDthe s3 prefix path containing the source files
sourceFilesOPTIONALIf not specified, by default it will include all files in the $sourcePath
targetBucketOPTIONALIf not specified, by default the $sourceBucket will be used as the $targetBucket
targetPathREQUIREDthe s3 prefix path to store the target files
targetFilesOPTIONALthe modified name of the files after moved. This should match the number of files in $sourceFiles, else it will fallback to the name in $sourceFiles. If not specified, by default it will use the name of the files in $sourceFiles.
createCopyOPTIONALIf not specified, by default it is set to false

Usage

  1. Move ALL files in the specified S3 sourcePath into the same S3 bucket.

    const s3mv = require('lambda-s3-mv');
    
    const result = await s3mv.move({
        sourceBucket: 's3-source-bucket-name',
        sourcePath: 's3-source-prefix-path',
        targetPath: 's3-target-prefix-path'
    });
    console.log(result);
    
  2. Move ALL files in the specified S3 sourcePath into different S3 bucket.

    const s3mv = require('lambda-s3-mv');
    
    const result = await s3mv.move({
        sourceBucket: 's3-source-bucket-name',
        sourcePath: 's3-source-prefix-path',
        targetBucket: 's3-target-bucket-name',
        targetPath: 's3-target-prefix-path'
    });
    console.log(result);
    
  3. Move specified list of files in the specified S3 sourcePath into the same S3 bucket.

    const s3mv = require('lambda-s3-mv');
    
    const result = await s3mv.move({
        sourceBucket: 's3-source-bucket-name',
        sourcePath: 's3-source-prefix-path',
        sourceFiles: ['source-file1.txt', 'source-file2.txt'],
        targetPath: 's3-target-prefix-path'
    });
    console.log(result);
    
  4. Move specified list of files in the specified S3 sourcePath into the same S3 bucket, and rename files after moved.

    const s3mv = require('lambda-s3-mv');
    
    const result = await s3mv.move({
        sourceBucket: 's3-source-bucket-name',
        sourcePath: 's3-source-prefix-path',
        sourceFiles: ['source-file1.txt', 'source-file2.txt'],
        targetPath: 's3-target-prefix-path',
        targetFiles: ['source-file1-moved.txt', 'source-file2-moved.txt']
    });
    console.log(result);
    
  5. Copy ALL files in the specified S3 sourcePath into the same S3 bucket. "createCopy" set to true.

    const s3mv = require('lambda-s3-mv');
    
    const result = await s3mv.move({
        sourceBucket: 's3-source-bucket-name',
        sourcePath: 's3-source-prefix-path',
        sourceFiles: ['source-file1.txt', 'source-file2.txt'],
        targetPath: 's3-target-prefix-path',
        createCopy: true
    });
    console.log(result);
    
Important

Please make sure the lambda has read and write access to specifed source S3 Bucket.

Sample Lambda using the lambda-s3-mv, with Cloudformation, can be found here.

Test

npm run test

Keywords

FAQs

Package last updated on 22 Feb 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc