‫So, this is to me one of the most
‫revolutionary services that AWS has to offer
‫and I think it is currently underutilized.
‫It's called AWS X-Ray and the exam is really
‫we want you to know about X-Ray.
‫I think this is why they ask two questions
‫because they want people to use it,
‫and I honestly think people should use X-Ray.
‫So, when you do debugging production
‫and I have debugged applications in production in the past,
‫the good old way, what I call the good old way
‫is test locally, add log statements everywhere
‫and redeploying production
‫and from the logs try to figure out
‫what is breaking, what is happening.
‫It's really painful.
‫It's not best practices.
‫Obviously, there are better ways of doing things.
‫I'm just oversimplifying things here, but you get the idea.
‫Debugging production is not fun.
‫And then, if you log stuff,
‫if you have different applications,
‫if you log from different applications to CloudWatch
‫then you know they all have different formats
‫and it's really hard to centralize insights.
‫And navigating CloudWatch logs is gonna be hard.
‫And analytics on top of it, it's going to be hard.
‫So, if you have a monolith, just one huge application
‫doing everything is sort of easy to debug,
‫but if you have distributed services
‫you're running a hundred microservices in your LS accounts,
‫it becomes a nightmare.
‫It's really, really hard to debug what's happening
‫because they all talk to each other, right?
‫So, there's no common view of your entire architecture,
‫your entire service map, et cetera.
‫So, here comes AWS X-Ray.
‫So, X-ray is going to give you a visual analysis
‫of your application.
‫So, this is what we're going to do in the hands-on.
‫We'll see that basically as a client doing a request
‫to our application we will see how many
‫of these requests fail or don't fail.
‫And then, from the application we'll see what it does.
‫So, it will call other IPs, it will call SNS
‫it will call a DynamoDB Table.
‫And so, as you can see, we'll be able to trace exactly,
‫visually what happens when we talk to our EC2 instance.
‫And so, you know from this graph
‫if I ask you where do you think
‫that little orange or yellow error comes from?
‫Well, is it coming from this?
‫No, is it coming from SNS?
‫No, it is coming from my DynamoDB Table.
‫You can see it visually.
‫And so, that's the whole power of tracing.
‫Obviously, you can do more, but you start getting the idea.
‫In terms of X-ray advantages, there's many.
‫You can troubleshoot the performance
‫of your application and identify bottlenecks.
‫You can understand the dependencies
‫in your microservice architecture
‫because you can visually see what is happening
‫and how all your microservices interact with one another.
‫We can pinpoint then which service is giving us issues.
‫We can understand how each request is behaving
‫and then find errors and exception based on the request.
‫We can answer questions such as, are we meeting time SLA
‫in terms of latency or time to process a request?
‫And we can understand which service
‫really slows down, throttles us.
‫Finally, we can know which users are impacted
‫by our errors if we wanted to.
‫So, X-ray has a lot of compatibility.
‫It's compatible with AWS Lambda, Beanstalk,
‫ECS, ELBs, API gateway, and EC2 instances
‫or any application server really,
‫even something you have on premise.
‫So, they really made X-Ray try to be as wide as possible
‫and as applicable as to any application they can.
‫So, X-Ray, how does it work?
‫Well, it leverages something called tracing.
‫And tracing is an end to a way
‫to basically follow a request.
‫So, when I make a request to, for example,
‫my application server, each component that will deal
‫with a request that could be my database,
‫that could be my gateway, my load balancer,
‫my application server.
‫Each component dealing with that request
‫will add its own trace, and so, the trace will be made
‫of segments and segments can be made of sub segments.
‫And the idea is that we can also add annotations
‫to traces to provide extra information around what happened.
‫So, when all these things are together,
‫you have the ability to trace every request
‫or a simple request.
‫So, you say I only want to get a percentage
‫of the total request or maybe five requests per minutes.
‫In terms of security, there is IAM authorization
‫and you can use KMS for encryption at rest.
‫So, once you get all these traces,
‫basically, X-Ray provides its magic
‫and provide this nice little graph that I showed you before.
‫Now, how do you enable X-Ray?
‫Well, you have two ways
‫and I think this is what the exam will ask you about.
‫So, you need to be very careful here.
‫Your code can be Java, Python, Go, Node.js and .Net
‫and it must import the AWS SDK.
‫You need very little code modification,
‫but you still need to do some code modification.
‫And then, the application SDK,
‫the X-Ray SDK, will then capture the calls
‫to the AWS services, the HTTP and HTTPS request
‫and the database calls for MySQL, PostgreSQL and DynamoDB.
‫It can also capture queue calls and so on.
‫Now, the second thing we have to do
‫once we've modified our code is to install the X-Ray daemon
‫or to enable the X-Ray AWS integration.
‫So, if we run on a machine, on-premise server
‫or EC2 instance, we need to install the daemon.
‫And the daemon is basically a little program that works
‫as a low level UDP packet interceptor.
‫It can be running on Linux, Windows, and Mac.
‫And so, you have to install it on your machine.
‫If you use AWS Lambda or other services
‫that already have integration with X-Ray
‫then they will run the daemon for you
‫and you don't have to worry about it.
‫Now, each application also must have the IAM rights
‫to write data to X-Ray.
‫So, a very common question is, hey, my X-Ray application
‫works on my computer when I test locally,
‫but doesn't work on my EC2 machine, why?
‫Well, the answer is probably because on your machine
‫you're running the X-Ray daemon,
‫but when you deploy to your EC2 instance,
‫it's not running the X-Ray daemon,
‫and therefore, X-Ray doesn't see your calls.
‫Now, to make it really crystal clear
‫here is an EC2 instance and you need to have
‫your application code on top of it.
‫And so, your code again needs to be modified
‫to import the AWS X-Ray SDK, and then it will send
‫its traces to the X-Ray daemon running the machine.
‫So, as you can see, you also need to run the X-Ray daemon
‫and that X-Ray daemon will send a batch
‫every one second to AWS X-Ray.
‫So, X-Ray does some magic.
‫And so, to update this graph, how does that work?
‫X-Ray will collect all the data
‫from all the different services sending traces,
‫and then, the service map will be computed magically
‫from all the segments and the traces.
‫And so, that's a really cool thing.
‫X-ray is graphical, so even non-technical people
‫can help troubleshoot.
‫Talking about trouble shooting,
‫what if X-Ray is not working on EC2?
‫As I said, you need to ensure that the IAM role
‫has the proper permission and you need to ensure
‫that the EC2 instance is indeed running the X-Ray Daemon.
‫If you want to run it on Lambda,
‫it's a little bit different.
‫For it, you need to ensure that the Lambda
‫has an IAM execution role with proper policy.
‫And I know we haven't seen what Lambda is,
‫but it's just a question you may get.
‫So, you need to make sure that Lambda has a proper IAM role
‫that's expected and then you need to ensure
‫that the X-Ray code is imported.
‫And finally, that you have activated the active
‫tracing Lambda option on X-Ray,
‫but we'll see this in the Lambda section as well.
‫So, that's it for the overview of X-Ray, a little taster.
‫In the next lecture, we're just going to run
‫the several apps on X-Ray to get a better feeling
‫of how it works.
‫So, see you in the next lecture.