In this tutorial, we aim to guide you on how to build a serverless API using Amazon's API Gateway. This will allow you to create, publish, maintain, monitor, and secure APIs without managing any servers.
Amazon API Gateway is a fully managed service that makes it easy to create, publish, maintain, monitor, and secure APIs. With a few clicks in the AWS Management Console, you can create an API that acts as a "front door" for applications to access data, business logic, or functionality from your back-end services.
# Choose 'Create Resource'
aws apigateway create-resource --rest-api-id abc123 --parent-id abc123xyz --path-part myresource
This command will create a new resource under the specified REST API (abc123
) and parent (abc123xyz
).
# Choose 'Create Method'
aws apigateway put-method --rest-api-id abc123 --resource-id xyz123 --http-method POST --authorization-type "NONE"
This will create a new POST method for the specified REST API (abc123
) and resource (xyz123
).
# Choose 'Deploy API'
aws apigateway create-deployment --rest-api-id abc123 --stage-name dev
This will deploy the API (abc123
) to the 'dev' stage.
In this tutorial, we have gone through the basics of Amazon's API Gateway, creating a serverless API, and deploying it. You can now create your own serverless APIs, deploy, and test them.
Exercise 1: Create a new API with a GET method which integrates with a Lambda function.
Exercise 2: Deploy the API created in Exercise 1 to a new stage called 'test'.
Exercise 3: Create a new resource under your API and add a PUT method to it.
Solutions:
1. Follow the same steps as above, but choose 'GET' instead of 'POST' when creating the method.
2. Follow the deployment steps, but use 'test' as the stage name.
3. Follow the steps to create a resource and method, but use 'PUT' instead of 'POST'.
Try adding more methods to your resources, such as DELETE and UPDATE. Test your APIs using different tools and integrate them with different AWS services.