Objective: Create an API Key named
StudentApiKey
in AWS API Gateway to secure the endpoints of thestudent
API (created in section 4.1), ensuring that only requests from the web interface (running on CloudFront) or clients with valid keys can access. The API Key will be used in thex-api-key
header when calling endpoints (GET /students
,POST /students
,POST /backup
) and will be linked to a Usage Plan (section 4.3) to manage access limits.
x-api-key
header of each HTTP request (e.g., GET https://api-id.execute-api.us-east-1.amazonaws.com/prod/students
).StudentApiKey
will secure the endpoints integrated with Lambda functions (getStudentData
, insertStudentData
, BackupDynamoDBAndSendEmail
).You need to complete section 4.1 (create the student
API) and section 3 (create Lambda functions getStudentData
, insertStudentData
, BackupDynamoDBAndSendEmail
, DynamoDB table studentData
, S3 bucket student-backup-20250706
, SES email verification). Ensure your AWS account is set up, and the AWS region is us-east-1
.
Access the AWS Management Console
Open your browser and log in to the AWS Management Console with your AWS account.
In the search bar at the top, type API Gateway and select the Amazon API Gateway service to access the management interface.
Check the AWS region: Make sure you are working in the primary AWS region (e.g., us-east-1
), and check the region at the top right corner of the AWS Console. This region should match the student
API (created in section 4.1) and Lambda functions (getStudentData
, insertStudentData
, BackupDynamoDBAndSendEmail
).
Figure 1: AWS Console Interface with API Gateway Search Bar.
Navigate to the API Keys Section
In the main Amazon API Gateway interface, look at the left navigation menu.
Select API Keys to view the list of existing API Keys. If you haven’t created any key, the list will be empty.
The interface will show options to create or manage API Keys.
Figure 2: Navigation Menu with API Keys Option.
Initiate the API Key Creation Process
In the API Keys interface, click the Create API Key button at the top right to start creating a new key.
Figure 3: Create API Key Button in the API Keys Interface.
Configure the API Key
In the Create API Key section:
StudentApiKey
exactly. This name helps you easily identify the key when linking it with the Usage Plan.Click Save to create the API Key.
Figure 4: API Key Configuration Interface.
Check the Status and Copy the API Key
After clicking Save, you will see the message: “Successfully created API Key ‘StudentApiKey’.”
In the API Keys list, select StudentApiKey
to view details.
Click Show next to API Key to display the key value (e.g., xxxxxxxxxxxxxxxxxxxx
).
Copy the API Key:
This API Key will be used in the web interface to call the endpoints (GET /students
, POST /students
, POST /backup
) by adding it in the x-api-key
header.
Figure 5: Success Message and API Key Details.
Element | Details |
---|---|
API Key Security | Do not embed the API Key directly in the JavaScript of the web interface (running on CloudFront). Instead, use environment variables or AWS Secrets Manager to securely store and retrieve the key. - Go to AWS Secrets Manager > Store a new secret > Choose Other type of secret > Enter the API Key. - Name the secret (e.g., student-api-key ) and retrieve it in the web interface code via the AWS SDK. |
AWS Region | The API Key operates across the entire AWS account, not limited by region. However, ensure that the student API and Lambda functions are in the same region (us-east-1 ) to avoid integration issues. |
Error Handling | If you do not see the success message or encounter an “AccessDenied” error: - Check if your AWS account IAM permissions include apigateway:POST to create API Keys. - Ensure you are in the correct AWS region (us-east-1 ). If the API Key does not show up, refresh the page or check the API Keys list again. |
Optimization | - After creating the key, link the API Key with a Usage Plan (section 4.3) to enforce access limits (rate limiting, quota). - Consider using AWS WAF with API Gateway for additional protection against attacks (e.g., DDoS). - If you need multiple API Keys (for different clients), create additional keys and manage them within the same Usage Plan. |
Early Testing | - After creating the API Key, verify that it appears in the API Keys list and that the key value is safely copied. - Test the key by making a request to the API (after configuring methods and deploying in steps 4.4–4.8) using Postman or curl: curl -X GET https://api-id.execute-api.us-east-1.amazonaws.com/prod/students -H "x-api-key: xxxxxxxxxxxxxxxxxxxx" |
Web Interface Integration Testing | - After creating the API Key, integrate the key into the web interface (using Tailwind CSS, running on CloudFront) to call the endpoints. - Ensure that the API Key is sent in the x-api-key header when calling the endpoints (GET /students , POST /students , POST /backup ). |
Practical Tip: Securely store the API Key immediately after creation and test the integration with a test request (using Postman or curl) before embedding it into the web interface.
The StudentApiKey
has been successfully created in AWS API Gateway, ready to be linked with a Usage Plan and secure the endpoints of the student
API.
Next step: Go to Set Up Usage Plan (Access Plan) to continue!