Developer keynote - if possible I want access to the example usecase -stripe event destination

Stripe event destination aws workflow => was demonstrated in the developer keynote. There was some json inputed into the aws event destiantion would love to try it out myself!

2 Likes

Hi @krish

Here’s the sample JSON that depicts the AWS workflow in the keynote. Note that you’ll need to spin up a few dependencies and reference them in your state machine definition to work:

State machine sample configuration

{
  "Comment": "A description of my state machine",
  "StartAt": "Fetch customer data from Stripe",
  "States": {
    "Fetch customer data from Stripe": {
      "Type": "Task",
      "Resource": "arn:aws:states:::http:invoke",
      "Parameters": {
        "ApiEndpoint.$": "States.Format('https://api.stripe.com/v1/customers/{}', $.detail.data.object.customer)",
        "Method": "GET",
        "Authentication": {
          "ConnectionArn": "{{YOUR CONNECTION}}"
        }
      },
      "Retry": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          "BackoffRate": 2,
          "IntervalSeconds": 1,
          "MaxAttempts": 3,
          "JitterStrategy": "FULL"
        }
      ],
      "Next": "Parallel"
    },
    "Parallel": {
      "Type": "Parallel",
      "Branches": [
        {
          "StartAt": "Update customer database",
          "States": {
            "Update customer database": {
              "Type": "Task",
              "Resource": "arn:aws:states:::dynamodb:updateItem",
              "Parameters": {
                "TableName": "customers",
                "Key": {
                  "id": {
                    "S.$": "$.ResponseBody.id"
                  }
                },
                "UpdateExpression": "SET email = :myValueRef",
                "ExpressionAttributeValues": {
                  ":myValueRef": {
                    "S.$": "$.ResponseBody.email"
                  }
                }
              },
              "End": true
            }
          }
        },
        {
          "StartAt": "Prepare payload",
          "States": {
            "Prepare payload": {
              "Type": "Pass",
              "Next": "Bedrock InvokeModel",
              "Parameters": {
                "text": {
                  "comments": ""
                }
              },
              "ResultPath": "$.ddb"
            },
            "Bedrock InvokeModel": {
              "Type": "Task",
              "Resource": "arn:aws:states:::bedrock:invokeModel",
              "Parameters": {
                "ModelId": "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-instant-v1",
                "Body": {
                  "prompt.$": "States.Format('\n\nHuman: {YOUR PROMPT},{} .\n\n Assistant:', $.ResponseBody.name,$.ddb.text.comments)",
                  "max_tokens_to_sample": 400
                }
              },
              "Next": "Sends personalized email to Slack for approval",
              "ResultSelector": {
                "completion.$": "$.Body.completion"
              },
              "ResultPath": "$.bedrock"
            },
            "Sends personalized email to Slack for approval": {
              "Type": "Task",
              "Resource": "arn:aws:states:::http:invoke",
              "Parameters": {
                "Method": "POST",
                "Authentication": {
                  "ConnectionArn": "{YOUR CONNECTION ARN}"
                },
                "RequestBody": {
                  "blocks": [
                    {
                      "type": "header",
                      "text": {
                        "type": "plain_text",
                        "text": "Approval request for new user email :envelope_with_arrow:",
                        "emoji": true
                      }
                    },
                    {
                      "type": "section",
                      "fields": [
                        {
                          "type": "mrkdwn",
                          "text": ":tada: We got a new user! Approve/regenerate the welcome email :tada:"
                        }
                      ]
                    },
                    {
                      "type": "divider"
                    },
                    {
                      "type": "rich_text",
                      "elements": [
                        {
                          "type": "rich_text_quote",
                          "elements": [
                            {
                              "type": "text",
                              "text.$": "$.bedrock.completion"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "type": "context",
                      "elements": [
                        {
                          "type": "mrkdwn",
                          "text": "Subject line: *Welcome to Hypernian - Day One of your creative AI journey!*"
                        }
                      ]
                    },
                    {
                      "type": "context",
                      "elements": [
                        {
                          "type": "mrkdwn",
                          "text": "Subscriber: $.ResponseBody.email"
                        }
                      ]
                    },
                    {
                      "type": "context",
                      "elements": [
                        {
                          "type": "mrkdwn",
                          "text": "Product: *Project+*"
                        }
                      ]
                    },
                    {
                      "type": "input",
                      "element": {
                        "type": "plain_text_input",
                        "multiline": true,
                        "action_id": "plain_text_input-action"
                      },
                      "label": {
                        "type": "plain_text",
                        "text": "Feedback for regeneration",
                        "emoji": true
                      }
                    },
                    {
                      "type": "actions",
                      "elements": [
                        {
                          "type": "button",
                          "text": {
                            "type": "plain_text",
                            "emoji": true,
                            "text": "Approve"
                          },
                          "style": "primary",
                          "value.$": "$$.Execution.Id"
                        },
                        {
                          "type": "button",
                          "text": {
                            "type": "plain_text",
                            "emoji": true,
                            "text": "Regenerate"
                          },
                          "style": "danger",
                          "value.$": "$$.Execution.Id"
                        }
                      ]
                    }
                  ]
                },
                "ApiEndpoint": "{{YOUR SLACK ENDPOINT}",
                "QueryParameters": {
                  "sendAsText": "true"
                },
                "Headers": {
                  "sendAsText": "true"
                }
              },
              "Retry": [
                {
                  "ErrorEquals": [
                    "States.ALL"
                  ],
                  "BackoffRate": 2,
                  "IntervalSeconds": 1,
                  "MaxAttempts": 3,
                  "JitterStrategy": "FULL"
                }
              ],
              "Next": "DynamoDB PutItem",
              "ResultPath": "$.api"
            },
            "DynamoDB PutItem": {
              "Type": "Task",
              "Resource": "arn:aws:states:::aws-sdk:dynamodb:putItem.waitForTaskToken",
              "Parameters": {
                "TableName": "sfn-executions",
                "Item": {
                  "PK": {
                    "S.$": "$$.Execution.Id"
                  },
                  "SK": {
                    "S": "demo"
                  },
                  "TT": {
                    "S.$": "$$.Task.Token"
                  }
                }
              },
              "Next": "Onboarding Message accepted?",
              "ResultPath": "$.ddb"
            },
            "Onboarding Message accepted?": {
              "Type": "Choice",
              "Choices": [
                {
                  "Variable": "$.ddb.action",
                  "StringEquals": "Approve",
                  "Next": "SNS Publish"
                }
              ],
              "Default": "Bedrock InvokeModel"
            },
            "SNS Publish": {
              "Type": "Task",
              "Resource": "arn:aws:states:::sns:publish",
              "Parameters": {
                "Message.$": "$",
                "TopicArn": "arn:aws:sns:us-east-1:992382636055:onboarding"
              },
              "End": true,
              "InputPath": "$.bedrock.completion"
            }
          }
        }
      ],
      "End": true
    }
  }
}
1 Like

thanks so much! Appreciate it!

1 Like