I am going to demonstrate how we can integrate Lambda function with API gateway.
GET API for fetching all running EC2 instances.
POST API for stopping one or more (all) running EC2 instances
Amazon API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale.
API developers can create APIs that access AWS or other web services, as well as data stored in the AWS Cloud.
As an API Gateway API developer, you can create APIs for use in your own client applications. Or you can make your APIs available to third-party app developers.
Support for stateful (WebSocket) and stateless (HTTP and REST) APIs.
Powerful, flexible authentication mechanisms, such as AWS Identity and Access Management policies, Lambda authorizer functions, and Amazon Cognito user pools.
Python boto3 code for fetching/ stopping all running EC2 instances:
https://github.com/prabhakar2020/aws_...
Lambda function: • AWS Lambda function | Copy files from one ...
EC2 Tutorial: • AWS Cloud EC2 introduction
AWS Complete tutorial - • AWS Cloud EC2 introduction