aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

fix: plumb outputStorageStrategy through conversation transformer to handler #3017

Closed atierian closed 1 week ago

atierian commented 1 week ago

Problem

The default lambda handler deployed for conversation routes via ai-constructs doesn't stream function logs for sandbox deployments when using the --stream-function-logs flag (documentation).

Description of changes

This allows ai-constructs to include the conversation handler Lambda function in the root stack outputs for streaming.

[!NOTE] https://github.com/aws-amplify/amplify-category-api/pull/3014 contains an alternative approach that also works, but involves duplicating the types into amplify-graphql-transformer-interfaces.

Relevant Backend PR

CDK / CloudFormation Parameters Changed

N/A

Issue #, if available

N/A

Description of how you validated changes

Manually tested. E2E test not feasible as construct only test; will look into options for automated testing in a follow up.

> npx ampx sandbox --identifier 'logs' --stream-function-logs
[Sandbox] Watching for file changes...
File written: amplify_outputs.json
# Send a message
[AssistantChatDefaultConversationHandler] 1:24:17 PM {"time":"2024-11-12T18:24:17.783Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v49","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:13821268cdb8b1fd3647b6b7f047e6989fdfa500ddcef1d207cab3e8aa30c617","functionName":"amplify-aismoketest-logs--AssistantChatDefaultConv-UxEQSg3XTyhZ","functionVersion":"$LATEST"}}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"time":"2024-11-12T18:24:18.153Z","type":"platform.start","record":{"requestId":"a9007650-3fad-4370-990c-db6646476e8e","version":"$LATEST"}}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"timestamp":"2024-11-12T18:24:18.154Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Handling conversation turn event, currentMessageId=cd831839-7a3e-42fb-8a45-eb302c33a5ca, conversationId=21c3ec83-c701-4ae9-8b7a-386e36f346b2"}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"timestamp":"2024-11-12T18:24:18.605Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Sending Bedrock Converse Stream request"}
[AssistantChatDefaultConversationHandler] 1:24:18 PM {"timestamp":"2024-11-12T18:24:18.868Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Received Bedrock Converse Stream response, requestId=a74da7bf-8f48-497d-8977-930d7f1a709b"}
[AssistantChatDefaultConversationHandler] 1:24:24 PM {"timestamp":"2024-11-12T18:24:24.254Z","level":"INFO","requestId":"a9007650-3fad-4370-990c-db6646476e8e","message":"Conversation turn event handled successfully, currentMessageId=cd831839-7a3e-42fb-8a45-eb302c33a5ca, conversationId=21c3ec83-c701-4ae9-8b7a-386e36f346b2"}
[AssistantChatDefaultConversationHandler] 1:24:24 PM {"time":"2024-11-12T18:24:24.257Z","type":"platform.report","record":{"requestId":"a9007650-3fad-4370-990c-db6646476e8e","metrics":{"durationMs":6104.742,"billedDurationMs":6105,"memorySizeMB":512,"maxMemoryUsedMB":124,"initDurationMs":368.411},"status":"success"}}

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.