Build a CRUD Serverless API with Python & AWS Lambda

In this video we walk you through Building a Serverless CRUD API with AWS Lambda, API Gateway and DynamoDB from Scratch

0:00 - Intro
0:58 - Database Creation (DynamoDB)
1:44 - Lambda Function Creation
4:13 - API Gateway Configuration
8:10 - Write the CRUD API Code in Python
21:28 - Update Lambda Code
22:02 - Test the Serverless API

Subscribe: https://www.youtube.com/c/FelixYu/featured 

#python 

What is GEEK

Buddha Community

Build a CRUD Serverless API with Python & AWS Lambda
Ryan  Schneider

Ryan Schneider

1595418900

Serverless Express – Easy APIs On AWS Lambda & AWS HTTP API

TLDR - Take existing Express.js apps and host them easily onto cheap, auto-scaling, serverless infrastructure on AWS Lambda and AWS HTTP API with Serverless Express. It’s packed loads of production-ready features, like custom domains, SSL certificates, canary deployments, and costs ~$0.000003 per request.

If you simply want to host a common Express.js Node.js application, have it auto-scale to billions of requests, and charge you only when it’s used, we have something special for you…

Announcing Serverless Express, a Serverless Framework offering enabling you to easily host and manage Express.js applications on AWS Lambda and the new AWS HTTP API, which is 60% faster and 71% cheaper than their initial API Gateway product.

Serverless Expess is a pure Express.js experience and it’s perfect for those that want to focus on apps, not infrastructure complexity.

Here are the highlights:

  • Easy, Safe, Performance - Includes the optimal infrastructure pattern for cost, performance & scale.
  • Never Pay For Idle - No API requests? No cost. Averages ~$0.000003 per request.
  • Zero Configuration - Add your Express app, then deploy (advanced config options are available).
  • Fast Deployments - Deploy changes to the cloud in seconds.
  • Real-time Logging - Rapidly develop on the cloud w/ real-time logs and errors in the CLI.
  • Canary Deployments - Deploy your app gradually to a subset of your traffic.
  • Custom Domain + SSL - Auto-configure a custom domain w/ a free AWS ACM SSL certificate.
  • Team Collaboration - Collaborate with your teamates with shared state and outputs.

Here is how to get started and deliver a Serverless Express.js based API with a custom domain, free SSL certificate and much more! You can also check out our Serverless Fullstack Application boilerplate, which includes Serverless Express in a real-world example that features a database, website using React and more.

Set-Up

Serverless Express is a Serverless Framework Component (i.e premium experiences for popular serverless use-cases) and you’ll need to install Node.js and the Serverless Framework CLI to use it.

Install Node.js here.

Then run this command to install Serverless Framework.

npm i -g serverless

Next, install the Serverless Express template:

serverless create --template-url https://github.com/serverless/components/tree/master/templates/express

Lastly, Serverless Express deploys onto your own Amazon Web Services account, so you’ll need Access Keys to an AWS account you own. Follow this guide to create those.

After you have created AWS Access Keys you can add them directly to an .env file, or reference an AWS Profile in a .env file, within the root of the template you installed.

AWS_ACCESS_KEY_ID=123456789
AWS_SECRET_ACCESS_KEY=123456789

You can also reference an AWS Profile in a .env file like this.

AWS_PROFILE=default

If you don’t include a .env file, the Serverless Framework will automatically look for a default AWS Profile in the root folder of your machine.

Also, Serverless Framework has a built-in stages concept. If you change the stage it will deploy a totally separate copy of your serverless application.

# serverless.yml
component: express@1.0.8
  name: express-api
  stage: prod

Even better, you can use different .env files for each stage by simply using this convention:

.env # all stages
.env.dev # "dev" stage
.env.prod # "prod" stage

One last—often overlooked—step is to install the Express.js dependency, by running npm i in the template.

#serverless #apis #aws #aws lambda #aws http api

Build & Deploy a Serverless CRUD REST API for S3 w/ API Gateway, AWS Lambda and Serverless

In this Serverless Saturday tutorial, we’ll be building a complete CRUD REST API for Amazon S3 using AWS Lambda and API Gateway. We’ll also be using the Serverless Framework along with GitHub Actions to set up a CI/CD pipeline that deploys our application to the AWS cloud.

Sections:
00:00 - Intro
00:32 - Set up IAM user to obtain deployment access keys
2:34 - Set up GitHub Actions CI/CD workflow
3:48 - Set up global config for serverless.yml
6:34 - Set up deployment config a new S3 bucket
8:10 - Set up deployment config for Lambda functions & API Gateway triggers
15:30 - Implementing the POST endpoint lambda handler
16:30 - Implementing the GET endpoint lambda handler
22:02 - Implementing the DELETE endpoint lambda handler
23:50 - Testing the CRUD REST API
28:22 - Wrap up

Other related tutorials:
Building the Image Upload Endpoint: https://www.youtube.com/watch?v=mWtnd-0Sm18
Deploying to AWS Lambda w/ the Serverless Framework & GitHub Actions (CI/CD): https://www.youtube.com/watch?v=oFYFqOzJdqY

Serverless Framework: https://www.serverless.com/
GitHub Actions: https://github.com/features/actions

Source Code: https://github.com/jacksonyuan-yt/s3-crud-api-gateway

Found this video helpful? Feel free to support this channel here: https://ko-fi.com/jacksonyuan

#rest api #lambda #aws #serverless

Build a Serverless API with AWS Gateway and Lambda

APIs are a crucial part of any web application and there are different techniques for development and design. Serverless is one approach gaining popularity, because of its cost-efficiency, scalability and relative simplicity. As a leading serverless provider, Amazon Web Services (AWS) has made a huge contribution to the world of serverless development, and in this article, we will explain general API implementation concepts using AWS Lambda and other AWS services.

Why AWS Lambda?

AWS Lambda is an AWS service that is responsible for running particular functions in response to particular triggers — events happening in the application. Those triggers could be HTTP calls; events from other AWS services like S3, Kinesis, or SNS; or just recurrent scheduled events. Functions are executed in some type of ephemeral containers, which are fully provisioned and scaled by AWS, so the development team can focus more on the code and functionality than on infrastructure.

Another attractive feature is the pay-as-you-go payment model, where you are charged only for the total execution time of your functions and do not pay for idle time. Of course, like any other service, Lambda has limits and is sometimes not suitable for certain tasks — such as very long-running jobs, heavy computing jobs, or processes that require control over the execution environment. However, AWS Lambda usually works perfectly for implementing APIs.

The Role of API Gateway

AWS API Gateway is a service allowing developers to create and manage HTTP endpoints, map them to particular AWS resources, and configure custom domains, authorizing mechanisms, caching and other features. API Gateway is the fundamental part of serverless API, because it is responsible for the connection between a defined API and the function handling requests to that API.

HTTP APIs

As mentioned, API Gateway includes a lot of functionality and integrations. At some point, though, Amazon realized that serverless developers usually do not require all of those features, but instead need a general simplification of the implementation process. That is probably why in late 2019, AWS announced the new HTTP APIs, a lite version of API Gateway, which dramatically simplifies the developer experience and provides better performance and lower costs for serverless APIs. Although it is simple, HTTP APIs still support such important features as configuring CORS for all endpoints, JWT integration, custom domains and VPC connections.

Understanding Serverless API Concepts

In order to easily understand the main concepts of serverless API implementation, we’ll build a very minimalistic example of a simple “virtual whiteboard” application, consisting of two simple endpoints: POST for writing messages on a whiteboard, and GET for fetching the three most recent messages. We will also consider other possible features — like path parameters, CORS, and authorizers — but we’ll keep the final implementation simple and clear to read.

AWS DynamoDB

We will make our project completely serverless, by using AWS DynamoDB for storing messages. This database corresponds to serverless principles, is easy to use, and offers a pay-per-request model that is really cost-effective. DynamoDB is a NoSQL key-value database offered by AWS, where your data is stored across AWS servers and fully managed by Amazon.

AWS Serverless Application Model

In order to continue further implementation, you’ll need an AWS account and AWS Serverless Application Model (SAM) installed and configured. SAM is a tool for creating, updating, and managing serverless applications and all the resources needed for the application to operate. With AWS SAM, you don’t need to create every single service manually via web console, but just to describe all the things needed in the special template file.

After you’ve installed the CLI, navigate to the directory you are going to work in and run this command:

$ sam init -r nodejs12.x -n whiteboard

Initializing new project

Select the first option, then select “Quick Start from Scratch.” This will create a “whiteboard” directory with a minimum of setup files inside.

#api management #aws #api #lambda #aws gateway #amazon web services

Ryan  Schneider

Ryan Schneider

1595434080

Git Actions with AWS Lambda Serverless Python Functions and API Gateway

Cloud is here to stay and more and more developers are seeking ways to effectively incorporate the cloud. Whether you are a startup recognizing limitations of your on-premise hardware and local machines or a large enterprise curious about how to slowly offload on-prem workloads, this tutorial will be insightful. I describe a phase 1 AWS architecture including Github, API Gateway, and AWS Lamba python functions. This represents an initial tutorial exposing developers to the AWS cloud adoption learning curve.

Notional Architecture:

Image for post

Architecture Diagram

The architecture above describes the basic CI/CD pipeline for deploying a python function with AWS Lambda. The developer represented above can pull and push their git repository to github using git. We configured the github actions YAML file to automatically update the AWS Lambda function once a pull request is merged to the master branch. The API Gateway represents a trigger which runs the AWS Lambda python function and returns a result. In this way, a Data Scientist (or analyst, frontend developer, or another developer) can trigger and access results in a quick and succinct fashion.

Note: AWS Lambda Functions exists in AWS Lambda, a compute resource inaccessible by the developer.

Purpose and Goals

This architecture represents an effective way for teams to build a robust CI/CD pipeline for application development and deployment. Though this architecture is “incomplete” with respect to a full-blown web application, this design can represent the first phase of building a web application. For anyone interested in offloading local compute resources, AWS Lambda serverless functions can be an effective way to leverage cloud in a cost-effective manner (AWS Lambda Functions are part of AWS always free tier). So many times, development teams design a lofty cloud based-architecture for application deployment (or migration) and fail. Conducting Proof-Of-Concepts and slowly incorporating cloud is more prudent.

#python #devops #api #data-science #aws-lambda #serverless

Zara  Bryant

Zara Bryant

1592533201

Serverless APIs with Python, AWS Lambda & API Gateway

Serverless APIs with Python, AWS Lambda & API Gateway

#serverless #python #aws #api #cloud