Skip to content

rtudo/s3-to-lambda-diff-checker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon S3 diff checker

The AWS SAM template deploys an AWS Lambda function and an Amazon S3 bucket with versioning enabled. The Lambda function is invoked when new objects are put into the bucket.

When versions of an object are uploaded, it logs out the difference between the latest version and the previous version. Using a configurable setting in template.yaml, it also deletes earlier versions of the object, retaining the most recent versions.

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

To learn more about how this application works, see the article on the AWS Compute Blog: https://aws.amazon.com/blogs/compute/building-a-difference-checker-with-amazon-s3-and-aws-lambda/.

.
├── README.MD                   <-- This instructions file
├── src                         <-- Source code for a lambda function
│   └── app.js                  <-- Main Lambda handler
│   └── processS3.js            <-- Processes each S3 object
│   └── deleteS3.js             <-- Removes earlier versions of an object
│   └── compareS3.js            <-- Compares most recent two versions
├── template.yaml               <-- SAM template

Requirements

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

    git clone https://github.com/aws-samples/s3-diff-checker
    
  2. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:

    sam build
    sam deploy --guided
    
  3. During the prompts:

    • Enter unique S3 bucket name
    • Enter the desired AWS Region
    • Allow SAM CLI to create IAM roles with the required permissions.

    Once you have run sam deploy -guided mode once and saved arguments to a configuration file (samconfig.toml), you can use sam deploy in future to use these defaults.

Testing

  1. Upload a TXT file the source S3 bucket.
  2. Make a change and upload again.
  3. Repeat this process, and note the output for the Lambda function, which logs out the differences in the versions and also deletes earlier versions of the object.

Cleanup

  1. Delete the stack
    aws cloudformation delete-stack --stack-name STACK_NAME
  2. Confirm the stack has been deleted
    aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Questions

Please contact the author or raise an issue on this GitHub repo if you have questions.


Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0

About

S3 to Lambda diff checker. Questions? Contact @jbesw.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%