You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过Amazon Connect将客户语音消息存储至S3存储桶

Got it, let's break down exactly how to store voice messages from your Amazon Connect contact flow into an S3 bucket, and crucially, tie each recording to the customer's phone number. Since you already have your contact workflow built, we'll focus on the storage and mapping pieces you're missing.

Step 1: Turn on Call Recording in Your Contact Flow

First, you need to enable recording within your existing contact flow. Here's how:

  • Open your Amazon Connect console, navigate to Contact Flows, and open the flow you're using.
  • Drag and drop the Set recording behavior block into your flow (place it early, ideally right after the customer connects).
  • Configure it to record either the entire call or specific segments (like when the customer leaves a voicemail, if that's your use case).
  • Make sure to set the recording trigger correctly—for voicemails, you might use the When customer is prompted to leave a message option.
Step 2: Capture the Customer's Phone Number

To link recordings to customer numbers, you need to grab that data from the contact attributes. You can do this two ways:

  • Directly in the contact flow: Use the Set contact attributes block to store the customer's number as a custom attribute. The variable for the incoming customer number is $.CustomerEndpoint.Address (for outbound calls, use $.SystemEndpoint.Address if you're initiating the call to the customer).
  • With a Lambda function: If you need to process the number (like formatting it, stripping country codes), add a Invoke AWS Lambda function block to your flow. Pass the $.CustomerEndpoint.Address as a parameter to Lambda, then have Lambda return the cleaned number as a contact attribute.
Step 3: Configure Amazon Connect to Send Recordings to S3

Now, set up the connection between Amazon Connect and your S3 bucket:

  1. Go to your Amazon Connect instance settings, select Data storage.
  2. Under Call recordings, click Edit and choose your target S3 bucket.
  3. Here's the key part: Customize the S3 prefix to include the customer number. Use the contact attribute you created earlier—for example, if you named your attribute customerPhone, the prefix could be:
    recordings/{instanceId}/{contactId}/{customerPhone}/
    
    This way, each recording's folder path will include the customer's number, making it easy to locate and associate later.
Step 4: Add Metadata to S3 Objects (Optional but Useful)

If you want to attach the customer number as metadata directly to the S3 object (instead of just in the path), use an EventBridge rule and Lambda:

  • Create an EventBridge rule that triggers when Amazon Connect finishes a recording (the event type is AWS::Connect::ContactRecording).
  • Configure the rule to invoke a Lambda function. The Lambda will receive event data containing the contactId, recordingS3Uri, and the contact attributes (including the customer number).
  • In the Lambda code, use the AWS SDK to update the S3 object's metadata. For example, in Python:
    import boto3
    
    s3 = boto3.client('s3')
    
    def lambda_handler(event, context):
        recording_uri = event['detail']['recordingS3Uri']
        bucket = recording_uri.split('/')[2]
        key = '/'.join(recording_uri.split('/')[3:])
        customer_phone = event['detail']['contactAttributes']['customerPhone']
    
        s3.copy_object(
            Bucket=bucket,
            Key=key,
            CopySource={'Bucket': bucket, 'Key': key},
            Metadata={'customer-phone': customer_phone},
            MetadataDirective='REPLACE'
        )
        return {'statusCode': 200}
    
  • Make sure your Lambda has permissions to read from EventBridge, access the S3 bucket, and modify object metadata.
Step 5: Test the Setup

Grab a test phone and call into your contact flow. After the call ends, check your S3 bucket:

  • Confirm the recording file exists in the prefix you set, including the customer number.
  • If you added metadata, view the S3 object's properties to verify the customer-phone metadata is present.

Quick Notes on Permissions

  • Ensure your Amazon Connect instance has an IAM role with s3:PutObject permissions for your target bucket.
  • If using Lambda, the Lambda execution role needs permissions for connect:GetContactAttributes, s3:GetObject, s3:PutObject, and events:PutRule.

内容的提问来源于stack exchange,提问作者Mohammad Shahadat Hossain

火山引擎 最新活动