Skip to content

A set of lambda functions created via sam (Serverless Application Model) for uploading files to a s3 bucket running on a nodeJS 10.x environment

Notifications You must be signed in to change notification settings

sebastianserrano/lambda-s3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to LambdaS3Upload 👋

Documentation Maintenance License: MIT

Upload file to s3 bucket via lambda function

.
├── README.MD                   <-- This instructions file
├── event.json                  <-- API Gateway Proxy Integration event payload
├── upload                      <-- Source code for a lambda function
│   └── app.js                  <-- Lambda function code
│   └── package.json            <-- NodeJS dependencies and scripts
│   └── tests                   <-- Unit tests
│       └── upload.test.js
├── template.yaml               <-- SAM template

Local development

Invoking function locally using a local sample payload

sam local invoke LambdaS3Upload --event event.json

Invoking function locally through local API Gateway

sam local start-api

If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function http://localhost:3000/upload

Packaging and deployment

AWS Lambda NodeJS runtime requires a flat folder with all dependencies including the application. SAM will use CodeUri property to know where to look up for both application and dependencies:

...
    LambdaS3Upload:
        Type: AWS::Serverless::Function
        Properties:
            CodeUri: upload/
            ...

Firstly, we need a S3 bucket where we can upload our Lambda functions packaged as ZIP before we deploy anything - If you don't have a S3 bucket to store code artifacts then this is a good time to create one:

aws s3 mb s3://BUCKET_NAME

Next, run the following command to package our Lambda function to S3:

sam package \
    --output-template-file packaged.yaml \
    --s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME

Next, the following command will create a Cloudformation Stack and deploy your SAM resources.

sam deploy \
    --template-file packaged.yaml \
    --stack-name lambda-s3-upload \
    --capabilities CAPABILITY_IAM

Install

npm install

Run tests

npm install
npm run test

Author

👤 Sebastian Serrano

📝 License

Copyright © 2019 Sebastian Serrano.
This project is MIT licensed.

About

A set of lambda functions created via sam (Serverless Application Model) for uploading files to a s3 bucket running on a nodeJS 10.x environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published