首页 > 解决方案 > 连接到 Kinesis 的不同 AWS 账户并从 MQ 中放入记录

问题描述

我有下面的代码应该连接到 Kinesis 的不同 AWS 账户并从 AWS MQ 中放置记录。

import time
import boto3
import json
from boto3 import Session

lambda_client = boto3.client('lambda')
kinesis_client = boto3.client('kinesis')

def lambda_handler(event, context):
    session = boto3.session.Session(aws_access_key_id= '', aws_secret_access_key= '',region_name='eu-aaa-1')
    kinesis_client = session.client('kinesis')
    print('received a message in worker : "%s"' % event)
    kinesis_client.put_record(
            StreamName='Stream_bookings',
            Data='event',
            PartitionKey='1'
        )

错误日志:-

{
  "errorMessage": "An error occurred (AccessDeniedException) when calling the PutRecord operation: User: arn:aws:iam::349928753634:user/svc.caspian-ingestion.onepurchase-uki-bookings-kinesis-test is not authorized to perform: kinesis:PutRecord on resource: arn:aws:kinesis:eu-central-1:349928753634:stream/CaspianStream_Onepurchase_UKI_bookings",
  "errorType": "ClientError",
  "stackTrace": [
    [
      "/var/task/op_worker.py",
      17,
      "lambda_handler",

我的政策:-

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "kinesis:PutRecord",
                "lambda:InvokeAsync",
                "lambda:InvokeFunction"
            ],
            "Resource": [
                "arn:aws:kinesis:eu-central-1:1234566789:stream/Stream_bookings"
            ]
        }
    ]
}

有没有可能我们可以在会话下传递 Arn 详细信息并发送记录

标签: pythonboto3amazon-kinesis

解决方案


推荐阅读