Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Attach a HTTP endpoint to an AWS Lambda function using the Serverless Framework


    Out of the box a AWS Lambda function is just an ephemeral container running our code. In order to invoke it and return a result we need to configure the AWS service API Gateway and connect it to our function.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: The Serverless Framework allows us to attach an HTTP endpoint to our lambda function for an event concept. In its simplest version, we define the path and the method. By the way, by default lambdas can only be invoked using the SDK.

    There are other AWS services like API Gateway that can invoke lambda and under the hood the framework actually is setting up an API Gateway for you, but abstracting away all the overhand. Once you start using the HTTP event, though, the expected response must be an object containing at least a status code as well as the body. In our case, we return a stringified JSON response.

    Now that everything is set up, we run sls deploy. Note that in this case, we can't run sls deploy function since we changed some configuration. In this case, the API Gateway service needs to be set up. After the deploy succeeded, we can use cURL to invoke the published endpoint.

    Voila! Works as expected.