Replies: 6 comments
-
We found out that X-Ray tracing needs to be enabled on the respective stage. The corresponding code would look like the one below. However, this overrides the automatically created stages AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Wild Rydes Asynchronous Messaging Workshop - Lab 2
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 10
Runtime: python3.9
Tags:
project: wild-rydes
workshop: asynchronous-messaging-workshop
author: aws
Resources:
SubmitRideCompletionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: unicorn-management-service/
Handler: app.lambda_handler
Environment:
Variables:
TABLE_NAME: !Ref RidesTable
TOPIC_ARN: !Ref RideCompletionTopic
Policies:
- DynamoDBCrudPolicy: # https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json
TableName: !Ref RidesTable
- SNSPublishMessagePolicy: # https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json
TopicName: !GetAtt RideCompletionTopic.TopicName
Tracing: Active
Events:
WildRydes:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /submit-ride-completion
Method: post
RestApiId: !Ref SubmitRideCompletionApi
SubmitRideCompletionApi:
Type: AWS::Serverless::Api
Properties:
TracingEnabled: true
StageName: Prod |
Beta Was this translation helpful? Give feedback.
-
To the first part of your question: To the second part of your question: |
Beta Was this translation helpful? Give feedback.
-
Hi @ssenchenko Got it, that makes sense. Would it be possible to highlight it in the documentation on how to enable X-Ray for the On a related note, how would I enable X-Ray for all of the other event sources that support tracing (SQS, SNS etc.)? There does not seem to be a corresponding I understand I could go the CloudFormation route and manually define those resources, but I would not be able to use the event source short-hand notation from SAM? |
Beta Was this translation helpful? Give feedback.
-
How would you rephrase the documentation or what would you add to make it clearer and intuitive? Your feedback is more important than whatever our team can add because you've had a problem with that part of the docs. As for SQS, SNS etc. the philosophy is the same as for Api. Event source merely connects function and an event in an intuitive way. Event source can generate an underlying resource or its part ie Api or SQS subscription for SNS event, but its configuration will be minimal. Sometimes, it's exactly what people need, for example while prototyping or for those who has just started with serverless and infrastructure as code. When full configuration is necessary, reference to an event source resource is the way to go. The way you did it for Api. For SQS for example Queue ARN is a required attribute anyway. For SNS Topic ARN is required and it's possible to pass Queue ARN for Subscription. |
Beta Was this translation helpful? Give feedback.
-
Hi @ssenchenko I understand the value of event sources and that they provide a short-hand notation to conveniently create underlying resources with minimal configuration. What might be counter-intuitive is that many of the SAM resources like What might add value is to capture the conversation here and add it to the documentation. The following would be my proposal:
None of the other event source types seem to be concerned when it comes to enabling AWS X-Ray active tracing. For example, the |
Beta Was this translation helpful? Give feedback.
-
From a developer perspective, this is what might be considered as inconsistent:
When using There is a corresponding In the example below, tracing is NOT enabled on the API gateway: AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Wild Rydes Asynchronous Messaging Workshop - Lab 2
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 10
Runtime: python3.9
Tags:
project: wild-rydes
workshop: asynchronous-messaging-workshop
author: aws
Api:
TracingEnabled: true # <-- does NOT apply to event source "Api". Applies only for dedicated AWS::Serverless::Api definitions
Resources:
SubmitRideCompletionFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: unicorn-management-service/
Handler: app.lambda_handler
Environment:
Variables:
TABLE_NAME: !Ref RidesTable
TOPIC_ARN: !Ref RideCompletionTopic
Policies:
- DynamoDBCrudPolicy: # https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json
TableName: !Ref RidesTable
- SNSPublishMessagePolicy: # https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json
TopicName: !GetAtt RideCompletionTopic.TopicName
Tracing: Active
Events:
WildRydes:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /submit-ride-completion
Method: post |
Beta Was this translation helpful? Give feedback.
-
Description
Given:
AWS::Serverless::Function
then it is no possible to enable X-Ray tracing on the API Event Source.
Steps to reproduce
Full source code: https://github.com/aws-samples/asynchronous-messaging-workshop/blob/master/code/lab-2/template.yaml
Observed result
With
Tracing: Active
set on theAWS::Serverless::Function
, the Lambda function has X-Ray tracing enabled.But the generated API Gateway does not have X-Ray tracing enabled. It is not possible to enable X-Ray tracing on the API Gateway event source, as there is no corresponding parameter for it available.
Expected result
Suggestions:
Tracing
parameter to allow enabling X-Ray for the API Gateway event sourceAdditional environment details
sam --version
: SAM CLI, version 1.53.0Beta Was this translation helpful? Give feedback.
All reactions