How to Verify the Deployed Sample Application
This document explains how to verify the operation of the reference implementation application deployed with AWS CloudFormation.
Initial Setup of the Database Deployed on AWS
The deployed VPC includes a bastion server with the SSM agent installed and VPC endpoints. Using these mechanisms, you can perform initial setup by connecting directly from your local PC to the database on AWS through port forwarding between the database in the private subnet and your local PC.
Create a session for port forwarding with the following command:
[Local PC ~]aws ssm start-session \
--target i-0287714efd175070c \ # Bastion Instance ID
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--region us-east-1 \
--profile <your AWS profile> \ # An instance profile with a policy that allows Systems Manager (SSM) actions is required.
--parameters '{"host":["db-postgresql-exljay17xqym.cluster-caextc42ljwl.us-east-1.rds.amazonaws.com"],"portNumber":["5432"],"localPortNumber":["5432"]}' # Writer instance endpoint of the DB stack deployed earlier
Download and install pgAdmin on your local PC for database operations from your local PC. Follow the steps below to create the database and tables that the application will reference using pgAdmin.
1. Server Registration
2. Enter Server Name
3. Host Configuration
Since port forwarding is being used, enter 127.0.0.1
or localhost
for the Host. Enter the Username and Password that you specified during AWS CloudFormation deployment. You can leave the Maintenance database as postgres
which is already entered.
4. Database Creation
5. Enter Database Name
You can enter any database name you like. In this example, we enter "mydb" and click Save to create the database.
6. Table Creation
Select the created mydb and open the Query Tool. From there, create the tables that will be used by the sample application.
7. Test Data Creation
Execute CREATE TABLE and INSERT statements from the query to create dummy data.
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
country VARCHAR(100),
age INTEGER
);
INSERT INTO users (name, country, age) VALUES
('Alice', 'Japan', 30),
('Bob', 'USA', 25),
('Charlie', 'Germany', 35);
SELECT * FROM users;
This completes the creation of the Database and Tables to be used by the application by connecting to the database from your local environment.
DynamoDB Setup
Inserting Test Data
This catalog also provisions an Amazon DynamoDB table. You can verify the table details in the Outputs section of the CloudFormation stack used to deploy the database.
You can insert the same test data into this table using the following AWS CLI commands.
[ec2-user ~]aws dynamodb put-item \
--region us-east-1 \
--table-name myapp-dev-Users \
--item '{
"id": {"N": "1"},
"name": {"S": "Alice"},
"country": {"S": "Japan"},
"age": {"N": "30"}
}'
[ec2-user ~]aws dynamodb put-item \
--region us-east-1 \
--table-name myapp-dev-Users \
--item '{
"id": {"N": "2"},
"name": {"S": "Bob"},
"country": {"S": "USA"},
"age": {"N": "25"}
}'
[ec2-user ~]aws dynamodb put-item \
--region us-east-1 \
--table-name myapp-dev-Users \
--item '{
"id": {"N": "3"},
"name": {"S": "Charlie"},
"country": {"S": "Germany"},
"age": {"N": "35"}
}'
When you check from the Management Console, you can confirm that the data has been inserted as shown below.
Verifying API Gateway + Lambda Application Operation
Let's check the API endpoint in the CloudFormation Output tab.
Let's execute a request using Postman or similar tools to the endpoint that retrieves user data with a GET method like https://<your API ID>.execute-api.us-east-1.amazonaws.com/dev/users?id=1
. You can see that the data for the user with id=1 registered in the database can be retrieved as shown below. (Note that in actual applications, you should avoid using auto-incremented IDs for user IDs for security reasons, as they make it easier for attackers to guess IDs. We recommend generating UUIDs or similar on the application side.)
Next, let's try registering user data via the API. Send a request to https://<your API ID>.execute-api.us-east-1.amazonaws.com/dev/users
using the POST method with the following Body parameters:
{
"name": "horike",
"country": "Japan",
"age": "41"
}
You can confirm that the data has been created correctly by checking with a SELECT statement from pgAdmin.
Verifying S3 + Lambda Application Operation
Let's check the bucket for uploading CSV files in the CloudFormation Output.
Upload a test CSV with the following command, and you can confirm that the CSV data is correctly stored in the database by checking with pgAdmin.
[ec2-user ~]aws s3 cp ./src/sample_users.csv s3://myapp-dev-<account-id>-upload-csv