Amazon Connect代理事件流提供了一个简单易用的方式来捕获云基础架构中基于事件的状态更改。在Amazon Connect代理事件流中,您可以将这些事件发送到其他AWS服务,如SNS。
以下是将数据从Amazon Connect代理事件流发送到SNS的示例代码:
import boto3 sns = boto3.client('sns') response = sns.create_topic(Name='event_topic') topic_arn = response['TopicArn']
import boto3
client = boto3.client('connect') response = client.list_instances() for instance in response['InstanceSummaryList']: instance_arn = instance['Arn'] response = client.list_contact_flows(InstanceId=instance_arn) for flow in response['ContactFlowSummaryList']: flow_arn = flow['Arn'] response = client.associate_contact_flow_with_instance( InstanceId=instance_arn, ContactFlowId=flow_arn ) response = client.start_instance( InstanceId=instance_arn ) print('Started instance:', instance_arn)
# Wait for the instance to become active
waiter = client.get_waiter('instance_active')
waiter.wait(InstanceId=instance_arn)
# Setup the event stream
start_response = client.start_contact_heartbeat(
InstanceId=instance_arn
)
event_stream_arn = start_response['ContactFlowEventStream']['Arn']
# Send the event stream to SNS
sns = boto3.client('sns')
sns.publish(TopicArn=topic_arn, Message=event_stream_arn)
# Stop the event stream
client.stop_contact_heartbeat(
InstanceId=instance_arn
)