A brief introduction to AWS Lamba and Application Programming Interface (API)

AWS Lambda lets us deploy code without provisioning or managing any servers. This makes it an incredible useful tool. All we need to do is upload our code and Lambda takes care of execution and scaling, ensuring high availability. Cost is only incurred for the compute time used, with no idle charges. Lambda also supports popular languages like Java, Node.js, C#, Python, and Ruby, allowing seamless integration with other AWS services or direct invocation from web and mobile applications.

Imagine you aim to minimize your Amazon EC2 service usage by halting instances during low-demand hours. For instance, you plan to stop EC2 instances at night when less capacity is required and restart them in the morning before the workday begins. You can use Lambda functions and Amazon CloudWatch Events to do this for you like so:

  • An Amazon CloudWatch Events event is scheduled to run a Lambda
  • function that stops your EC2 instances at (for example) 22:00 Universal Coordinated Time (UTC).
  • The Lambda function is triggered, and it function runs with the IAM role that grants it permissions to stop the EC2 instances. Lambda can handle up to 1,000 concurrent function invocations in a single Region.
  • The EC2 instances enter the stopped state.
  • Later, at 05:00 AM UTC (for example), a CloudWatch Events event is scheduled to run a Lambda function to start the EC2 instances.
  • The Lambda function is triggered and it runs with the IAM role that grants it permissions to start the EC2 instances.
  • The EC2 instances enter the running state.

AWS Lambda is categorized as serverless computing. So this is PaaS - platform as a service. The benefit of this is you don't need to manage the servers yourself, but that's instead left to the cloud provider. However, some key considerations if you're wanting to go cloud native;

  • The maximum memory allocation for a single Lambda function is 3 GB.
  • The maximum execution time for a Lambda function is 15 minutes.

So what is an Application Programming Interface (API)?

Simply they are a way for two computer programs to interact. So in essence, they provide programmatic access to an application. HTTP API exist but the more sophisticated protocol is the REST API.

The six design principles of REST:

  • A uniform interface
  • Stateless
  • Client-server architecture
  • Cacheable
  • Layered system
  • Code on demand (optional)

A REST request includes several components:

  • Endpoint: Specifies the URL where the desired resource is located on the server. Clients use the endpoint to communicate with the server about the intended interaction.

  • Method: Defines the operation to be performed on the resource. Common methods include
    • GET: Server is requested to retrieve a resource.
    • POST: Server is requested to create a new resource.
    • PUT: Server is requested to edit or update an existing resource.
    • DELETE: Server is requested to delete a resource.
  • Header: Contains metadata providing additional information about the request, aiding in communication between the client and server.

  • Body: The data sent from the client to the server, typically present in POST or PUT requests. For instance, a PUT request might include details on how an existing resource should be updated. GET requests, focused on retrieval, usually do not include a body.

In a similar way to car OBD error codes, API's also have hundreds of status codes. Similarly, the initial digit of the three numbers indicate the general nature of the status. Here are some common HTTP status codes:
  • 200 – Indicates success. The server received and accepted the request.
  • 401 – Indicates a client error, Unauthorized. Authentication is required, but the provided credentials were not accepted, or perhaps no credentials were provided in the request.
  • 403 – Indicates a client error, Forbidden. The request was properly made, but the server is not allowing the request.
  • 404 – Indicates a client error, Not Found. The resource is unavailable or could not be accessed.
  • 500 – Indicates an unspecific internal server error. 503 – Indicates that the service is temporarily unavailable

AWS API gateways provide us a single point of gateways for a number of API's for the backend of our application. The major benefits of using such a service are for;
  • Authentication and security policy enforcements
  • Load balancing and circuit breaking
  • Protocol translation and service discovery
  • Monitoring, logging, analytics and billing

API Gateway, integrated with Amazon CloudFront, utilizes edge locations for low-latency API requests. Once deployed, API Gateway offers a monitoring dashboard for service calls. Client apps interact through the frontend, while the backend handles communication with other AWS services.

Popular posts from this blog

Network Fundamentals for the Cloud

Familiarizing with the Command Line Interface

Security Fundamentals for the Cloud

CLI Fundamentals for the Cloud

DataDog, a Cloud Analytics & Monitoring application

A brief introduction to Databases and MySQL

AWS CodeCommit + Creating a CI/CD pipeline

Future Orientation: Tips from a AWS re/Start Graduate

A brief introduction to AWS Cloud Adoption Framework (CAF) and Well-Architected Framework (WAF)

Building a VPC in AWS