GithubHelp home page GithubHelp logo

isabella232 / serverless-inline-lambda Goto Github PK

View Code? Open in Web Editor NEW

This project forked from binxio/serverless-inline-lambda

0.0 0.0 0.0 5 KB

Deploying a Serverless Lambda function with API gateway using a Custom Resource in CloudFormation using Rubycfn

Ruby 47.64% Python 52.36%

serverless-inline-lambda's Introduction

Serverless and in-line Lambda

AWS has support for Serverless transformations, however: it requires you to upload the Lambda function to S3 prior to deployment. The reason for this is that the CodeUri property of an AWS::Serverless::Function cannot use intrinsic functions and thus you must hardcode the s3 artifact URL into your template.

If you want to automate this process, your CI CD pipeline has to upload the Lambda function to S3 first. The disadvantage of that practice is that the code of your Lambda function is not versioned. It would be if we could use the Lambda in-line. However, maintaining in-line Lambda in CloudFormation is rather ugly.

Solution

To work around this limitation I've created a small script with Rubycfn. This script converts your Lambda function file to in-line code in CloudFormation, so that you only have to maintain the file containing your Lambda code.

In addition, the CloudFormation template contains a Custom Resource that creates a zip file from your in-line Lambda and uploads it to S3.

Et voila! You can now deploy the CloudFormation template, while keeping your Lambda function under version control and keeping it maintainable.

This demo assumes you have Ruby installed. Ruby 2.3 or higher is recommended.

Creating the Template

gem install rubycfn
https://github.com/binxio/serverless-inline-lambda.git
cd serverless-inline-lambda
export DEMO_BUCKET="my-s3-bucket"
cat template.rb | rubycfn > my_template.json

And you're done! Don't forget to export DEMO_BUCKET to an S3 bucket that you own.

serverless-inline-lambda's People

Contributors

dennisvink avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.