This project contains source code and supporting files for a serverless application that you can deploy with the SAM CLI. It includes the following files and folders.
- Maven
- Java 11
- SAM CLI (install)
- AWS CLI (install)
- POSTMAN Tool
- OS: Windows 10 (can also be done on other Platforms if the Installation of AWS and SAM CLI's is done properly)
Note: Don't Forget to setup the AWS CLI using the AccessKey and SecretKey which you will get when an IAM USER is created in the AWS
Step 1: Open the Powershell in the particular respective folder ordersapi
Step 2: Use the following build command
sam build
Step 3: Use the following deploy command to package and deploy your application to AWS
sam deploy
Note: Here we are not using the --guided in the command since the repo files already built and deployed.
- Go to --> API Gateway in AWS --> ordersapi--> select Stages on the left side panel menu --> press on stages--> Copy the URL
- If Deployed Successfully you should see an GET and POST names in the Resources panel, as shown below:
/orders
GET
POST
- Open PostMan Tool
- Select the POST method
- Paste the URL
- Select Body --> raw-->JSON and paste the following JSON data
{
"id": "1",
"itemName": "dog",
"quantity": 100
}
- Press Send
Output:
Order ID: 123
Note: Make sure in Authorization select TYPE as AWS Signature in the drop-down menu and don't forget to put the AccessKey and SecretKey which you will get when an IAM USER is created in the AWS which is also required to setup the AWS CLI.
- Select the GET method
- Paste the URL
- Body --> None
- Press Send
Output:
{
"id": "1",
"itemName": "dog",
"quantity": 100
}
Note: If more than one POST method is submitted using differnt id, itemName and quantity in the JSON, after that you use the GET Method then the output will be more than one JSON. For Example, the OUTPUT of GET method, after two many POST methods
[
{
"id": 79,
"itemName": "CAT",
"quantity": 121
},
{
"id": 78,
"itemName": "dog",
"quantity": 100
}
]
See the AWS SAM developer guide for an introduction to SAM specification, the SAM CLI, and serverless application concepts.