Skip to content

Instantly share code, notes, and snippets.

@skwashd
Created May 19, 2025 04:42
Show Gist options
  • Save skwashd/0aa4c702b7ab4eed64a729a9860b3044 to your computer and use it in GitHub Desktop.
Save skwashd/0aa4c702b7ab4eed64a729a9860b3044 to your computer and use it in GitHub Desktop.
Code for Summarising Support Tickets with Amazon Nova Lite

This is the Step Function definition used in my Summarising Support Tickets with Amazon Nova Lite post.

Replace the following tokens in the file:

  • {{ACCOUNT_ID}} - the ID of your AWS account
  • {{REGION}} - the region you are running the Step Function in

This state machine workflow depends on the PicoFun Zendesk example project to generate the Lambda functions for the Zendesk API endpoints.

Flow

AWS Step Functions flow showing getting the comments, removing duplicates, invoking the Nova model via Amazon Bedrock and finally posting the summary.

Proactive Ops Newsletter

Subscribe to the ProactiveOps Newsletter so you don't miss great content like this.

{
"Comment": "A description of my state machine",
"StartAt": "GetComments",
"States": {
"GetComments": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Output": "{% $filter($states.result.Payload.body.comments, function($o) {$not($contains($o.plain_body, '\n This summary was generated by Amazon Nova'))}) ~> $map(function($o) {$o.plain_body}) %}",
"Arguments": {
"FunctionName": "arn:aws:lambda:us-east-1:905418209996:function:zendesk_get_api_v2_tickets_ticket_id_comments:$LATEST",
"Payload": {
"path": {
"ticket_id": "{% $states.input.ticket_id %}"
}
}
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 1,
"MaxAttempts": 3,
"BackoffRate": 2,
"JitterStrategy": "FULL"
}
],
"Assign": {
"ticket_id": "{% $states.input.ticket_id %}"
},
"Next": "SingleComment?"
},
"SingleComment?": {
"Type": "Choice",
"Choices": [
{
"Condition": "{% $type($states.input) != \"array\" %}",
"Next": "NoAction"
}
],
"Default": "SummariseTicket"
},
"NoAction": {
"Type": "Succeed",
"Comment": "If a ticket only has a single comment, we won't waste our time summarising it."
},
"SummariseTicket": {
"Type": "Task",
"Resource": "arn:aws:states:::bedrock:invokeModel",
"Next": "PutComment",
"Arguments": {
"ModelId": "arn:aws:bedrock:us-east-1::foundation-model/amazon.nova-lite-v1:0",
"Body": {
"system": [
{
"text": "You are to summarise the comments posted on a support ticket. Format the output as markdown. Headings are to be h2 level. Format the template with the following headings:\n * Problem\n * Actions taken \n\nInclude any other relevant information that will assist the reader in understanding what happened in the ticket."
}
],
"messages": "{% $map($states.input, function($s) {{'role':'user','content':[{'text':$s}]}})%}",
"inferenceConfig": {
"temperature": 0.1,
"topP": 1,
"maxTokens": 512
}
}
},
"Output": {
"summary": "{% $states.result.Body.output.message.content[0].text %}"
}
},
"PutComment": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Output": "{% $states.result.Payload %}",
"Arguments": {
"FunctionName": "arn:aws:lambda:us-east-1:905418209996:function:zendesk_put_api_v2_tickets_ticket_id:$LATEST",
"Payload": {
"path": {
"ticket_id": "{% $ticket_id %}"
},
"payload": {
"ticket": {
"comment": {
"body": "{% $join([$states.input.summary, ' ', ' ', 'This summary was generated by Amazon Nova', ' '], '\n') /* The spaces for new empty lines */ %}",
"public": false
}
}
}
}
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException",
"Lambda.TooManyRequestsException"
],
"IntervalSeconds": 1,
"MaxAttempts": 3,
"BackoffRate": 2,
"JitterStrategy": "FULL"
}
],
"End": true
}
},
"QueryLanguage": "JSONata"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment