AWS:将事件桥事件转发到加密的SQS(使用Amazon管理的密钥)
创始人
2024-09-28 08:00:24
0

以下是一个使用AWS SDK for Python(Boto3)的示例代码,将Amazon EventBridge事件转发到加密的SQS队列(使用Amazon管理的密钥):

import boto3

def create_event_bridge_rule(source, detail_type, target_arn):
    client = boto3.client('events')
    
    response = client.put_rule(
        Name='my-event-bridge-rule',
        EventPattern={
            'source': [source],
            'detail-type': [detail_type]
        },
        State='ENABLED',
        Description='My EventBridge rule',
    )
    
    response = client.put_targets(
        Rule='my-event-bridge-rule',
        Targets=[
            {
                'Id': '1',
                'Arn': target_arn,
            }
        ]
    )
    
    return response

def create_encrypted_sqs_queue(queue_name):
    client = boto3.client('sqs')
    
    response = client.create_queue(
        QueueName=queue_name,
        Attributes={
            'KmsMasterKeyId': 'alias/aws/sqs',
            'KmsDataKeyReusePeriodSeconds': '300'
        }
    )
    
    return response['QueueUrl']

def add_permission_to_sqs_queue(queue_url, account_id):
    client = boto3.client('sqs')
    
    response = client.add_permission(
        QueueUrl=queue_url,
        Label='event-bridge',
        AWSAccountId=[account_id],
        Actions=['SQS:SendMessage']
    )
    
    return response

# 创建加密的SQS队列
queue_name = 'my-encrypted-sqs-queue'
queue_url = create_encrypted_sqs_queue(queue_name)

# 将事件桥规则与SQS队列关联
source = 'aws.ec2'
detail_type = 'EC2 Instance State-change Notification'
target_arn = queue_url
create_event_bridge_rule(source, detail_type, target_arn)

# 授予事件桥权限发送消息到SQS队列
account_id = boto3.client('sts').get_caller_identity().get('Account')
add_permission_to_sqs_queue(queue_url, account_id)

以上代码示例中,create_event_bridge_rule函数用于创建事件桥规则,create_encrypted_sqs_queue函数用于创建加密的SQS队列,add_permission_to_sqs_queue函数用于向SQS队列添加权限。

在使用代码示例之前,请确保已正确配置AWS CLI或AWS SDK,默认凭证提供程序和区域设置。

相关内容

热门资讯

微扑克德州专用辅助器!德州俱乐... 微扑克德州专用辅助器!德州俱乐部俱乐部系统(透视)确实是真的有挂(详细辅助曝光教程)1、不需要AI权...
透视辅助!wepoke插件,w... 透视辅助!wepoke插件,wepoke有挂吗网上靠谱吗,详细透视大神讲解wepoke插件辅助器中分...
透视能赢!WePoKe外 挂,... 透视能赢!WePoKe外 挂,wepoke机制,详细透视详细教程;1、WePoKe外 挂透视辅助简单...
wepoke辅助技巧!微扑克有... 一、wepoke辅助技巧简介了解软件请加微:136704302wepoke辅助技巧是一款在线扑克游戏...
德扑数据软件!aapoker辅... 德扑数据软件!aapoker辅助是真的吗(透视)都是是真的有挂(详细辅助微扑克教程)(1)德扑数据软...
透视有挂!wepokeai代打... 透视有挂!wepokeai代打,wepoke辅助是真的,详细透视普及教程1、wepokeai代打系统...
德扑数据软件!wpk输赢机制(... 德扑数据软件!wpk输赢机制(透视)一直是有挂(详细辅助插件教程)1、德扑数据软件ai辅助优化,德扑...
透视ai代打!wepoke黑科... 透视ai代打!wepoke黑科技,wepower有辅助软件吗,详细透视教你教程1、点击下载安装,we...
德州ai辅助软件!pokern... 德州ai辅助软件!pokernow怎么加注(透视)从前真的是有挂(详细辅助透牌教程)您好,德州ai辅...
透视讲解!wepoke辅助,w... 透视讲解!wepoke辅助,wepoke真的,详细透视爆料教程1、在wepoke辅助ai机器人技巧中...