I made something like this before, but I experimented to see what I could understand by visualizing it with AWS X-Ray.
I tried to operate Amazon Athena from AWS Lambda
The AWS X-Ray SDK doesn't seem to send Trace data directly to AWS X-Ray, so create an EC2 instance for sending. It's easy because you just register the following as user data and create an instance.
#!/bin/bash
curl https://s3.dualstack.us-east-1.amazonaws.com/aws-xray-assets.us-east-1/xray-daemon/aws-xray-daemon-2.x.rpm -o /home/ec2-user/xray.rpm
yum install -y /home/ec2-user/xray.rpm
The xray installation log was output to the system log, so it should be OK.
Examining /home/ec2-user/xray.rpm: xray-2.0.0-1.x86_64
Marking /home/ec2-user/xray.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package xray.x86_64 0:2.0.0-1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
xray x86_64 2.0.0-1 /xray 6.6 M
Transaction Summary
================================================================================
Install 1 Package
Total size: 6.6 M
Installed size: 6.6 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : xray-2.0.0-1.x86_64 1/1
xray start/running, process 2576
Verifying : xray-2.0.0-1.x86_64 1/1
Installed:
xray.x86_64 0:2.0.0-1
Complete!
I am running a Java application this time, but if you want to monitor the Lambda application with X-Ray, it seems that you only need to select the following check box in the "Settings" tab of the Lambda application.
Reference: http://docs.aws.amazon.com/ja_jp/xray/latest/devguide/xray-services.html
You also need to set permissions in IAM to operate X-Ray. Since this was a trial operation, I added "AWS Xray Full Access", but I would like to carefully select this area according to the actual operation.
If you can do so far, you can run the Lambda app normally and see what it looks like in X-Ray. This time, I gave the following JSON as input to the Lambda application. It is an input value when data is fetched from Athena's table as a sample in the previous article.
{
"region": "us-east-1",
"s3Path": "s3://ishida-athena-staging-dir/",
"sql": "SELECT elbname, requestip, requestport, backendip, backendport, requestprocessingtime, backendprocessingtime, timestamp FROM sampledb.elb_logs order by timestamp desc limit 10",
"columnListStr": "elbname, requestip, requestport, backendip, backendport, requestprocessingtime, backendprocessingtime, timestamp"
}
After waiting for about 1 minute after execution, the following display was confirmed on X-Ray. It seems that the visualization was successful.
When I clicked on the object on the right side of the displayed Service Map, the following was displayed.
You can see in a list how long each process takes and what is returned as a response. Clicking on the displayed ID confirmed the details of that Trace.
As far as I can see, it takes about 230ms to initialize the Lambda application, and about 3 seconds to the actual Athena connection part. This process takes 4.6 seconds as a whole, so it should be understood that it takes about 1.5 seconds other than actually accessing Athena. I need more study in this area (^^;
By the way, if there is an error, it seems that you can also check the contents of the exception.
How long each process takes, and it is powerful to be able to visualize while setting up the calling relationship so easily. Considering that it will become commonplace to distribute processing with Microservices etc. from now on, it can be said that it is an indispensable technology. Speaking of Spring, it feels like Zipkin and Sleuth are realized on AWS.
Recommended Posts