Code Monkey home page Code Monkey logo

aws-serverless-cf-template's Introduction

serverless-cf-template

Build Status

AWS CloudFormation template creating a Serverless application using AWS Lambda and API Gateway

Description

This AWS CloudFormation solution deploys a simple AWS serverless example endpoint application. Serverless eliminates infrastructure management tasks such as server or cluster provisioning, patching, operating system maintenance, and capacity provisioning. This AWS CloudFormation template creates an AWS API Gateway deployment for handling a RESTful request and AWS Lambda function written in Python.

Serverless enables you to build modern applications with increased agility and lower total cost of ownership. Serverless allows you to build and run applications and services without thinking about servers. You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you.

Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no charge when your code is not running.

AWS Serverless

AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.

AWS Resource Costs

As with most AWS services you will incur costs for usage. For this CloudFormation template the resources that incur costs are as follows

Prerequisites

  • Amazon Web Services Account
  • IAM User with the following permissions:
    • AWSCloudFormationReadOnlyAccess
    • AmazonAPIGatewayAdministrator
    • AWSLambdaFullAccess
    • AmazonS3FullAccess
  • IAM Role named serverless (if you change the name make sure to change it in the template) with the following permissions:
    • AmazonAPIGatewayInvokeFullAccess
    • AWSLambdaExecute
    • AWSLambdaRole
    • Role Trust Relationship set to the below:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "apigateway.amazonaws.com",
          "lambda.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

CloudFormation Template

  • The CloudFormation Template is available on GitHub:

  • This CloudFormation states where the Lambda application exists, what it is named along with some configuration settings such as memory allocated, timeout for the application, runtime interpreter, and also creates an API Gateway endpoint with the proper handling of HTTP response codes in concert with the Lambda application.

  • Things to change or note in the CloudFormation Template

    • Change your S3Bucket to the name of your bucket where you put the lambda.zip
    • If you made your own role name change the role name in two places from "role/serverless" to the role name you created

AWS Lambda function in Python

  • lambda.zip (located in the lambda-app folder in the repo)
    • This is a compressed zip file of lambda-app.py which is a simple function which when called outputs hard coded sample JSON. Lambda reads this zip file and uses the designated interpreter to execute it. In this example we are using Python as our language and the Python interpreter.
    • Make sure you upload it to the S3 bucket you are using and named in your CloudFormation template.

Deploy the CloudFormation Template

  • AWS Management Console

    • Login to AWS Management Console
    • Launch under CloudFormation your edited serverless-cf-template.yml (included in this repo)
  • CloudFormation Fields:

    • Stack name (Enter a name to associate to your AWS Serverless deployment)
    • Continue choosing Next and then Create (it may take several mintues to create resources)

Results of the CloudFormation Template

In the AWS Management Console you should be able to verify the following have been created.

  • Resources Created:
    • An API Gateway Deployment
    • A Python Lambda Function
    • Test using the URL provided in the CloudFormation Outputs under TestURL in a browser, you should see the following JSON output:
{"data": {"a": 1, "c": 3, "b": 2}}

aws-serverless-cf-template's People

Contributors

nethacker avatar

Watchers

James Cloos 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.