Today, we'll be looking at a case study based around the company ProductCorp. ProductCorp is going through a period of rapid expansion, and they've decided to set up a secure API so that their support staff can access basic information easily. To begin with, we'll set up the API Gateway with a GET route to fetch client data.
It is highly recommended to provision a Cloud9 environment for this lab, as Cloud9 comes with all of the tools we need already installed. Follow the instructions provided by AWS to do this.
Load up the Cloud9 environment that you just provisioned. In the terminal window at the bottom, run the following command:
git clone [email protected]:lisushka/secure-api-gateway
You should now see the files in this repository in the sidebar of your Cloud9 IDE.
-
In the AWS console, go to
IAM
>Users
, and clickAdd user
. -
Under
Access type
, selectProgrammatic access
. Go to the next step, and selectAttach existing policies directly
. Attach theAdministratorAccess
policy, and then click through to review and create the user. An access key pair will be displayed on screen - we'll need this to configure the CLI profile.
-
In the Cloud9 terminal, run
aws configure
. -
For
AWS Access Key ID
, copy the access key ID from the IAM console (this always begins with the lettersAK
). -
For
AWS Secret Access Key
, copy the secret access key from the IAM console (you may have to unhide it). -
For the
Default region name
, useus-east-1
. Leave the default output format blank.
Once the AWS CLI is configured in Cloud9, we can deploy the template using the following commands:
secure-api-gateway $ aws cloudformation deploy --stack-name secure-api-stack --template-file step1/cf.yaml --capabilities CAPABILITY_IAM
You can test the API Gateway using the Postman application, if you have it installed. Otherwise, you can hit the API endpoint using cURL
-
In the AWS console, open the API gateway landing page. Click on the
ProductCorp_SupportApi
. -
In the sidebar, click on
Stages
, and then open theprod
stage. At the top of the console page, there will be a blue bar with an Invoke URL. Copy this URL - we'll need it in the next step. -
Run the following command in the Cloud9 terminal:
curl https://<your-api-url>/test
You should receive a response that reads "Welcome to the ProductCorp Support API!"
-
In the AWS console, open the API gateway landing page. Click on the
ProductCorp_SupportApi
. -
In the sidebar, click on
Stages
, and then open theprod
stage. At the top of the console page, there will be a blue bar with an Invoke URL. Copy this URL - we'll need it in the next step. -
Enter your Invoke URL in the Postman address bar, with
/test
appended. -
Change the HTTP request method to
GET
. -
Click the
Send
button. You should receive a response that reads "Welcome to the ProductCorp Support API!"