AWS Kinesis Put record from one AWS account to dif

2019-02-21 07:32发布

I followed different links but none were useful to me. My final moto is to put messages received from MQ to different account of Kinesis data stream.

Edited code accordingly which uses sts_client:-

import time
import boto3
import stomp
import json

class Listener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)

    def on_message(self, headers, message):
        print('received a message "%s"' % message)
        kinesis_client.put_record(
            StreamName='',
            Data=u'{}\r\n'.format(message).encode('utf-8'),
            PartitionKey='0'
        )
sts_client = boto3.client('sts')
kinesis_client = boto3.client(region_name="eu-central-1",aws_access_key_id = sts_response['Credentials']['AccessKeyId'],aws_secret_access_key = sts_response['Credentials']['SecretAccessKey'])

def lambda_handler(event, context):
    sts_response = client.assume_role(RoleArn='arn:aws:iam::12345678910:role/project-ppl-bookings-kinesis')
    conn = stomp.Connection(host_and_ports=[('b-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 61614)])
    lst = Listener()
    conn.set_listener('Listener', lst)
    conn.set_ssl(for_hosts=[('b-4714-4441-8166-47aae158281a-1.mq.eu-central-1.amazonaws.com', 61614)])
    conn.start()
    print('CONNECTION Started')
    conn.connect(login='test_mq', passcode='',wait=True)
    print('CONNECTION established')
    conn.subscribe(destination='/queue/OnePurchasing', id=1, ack='auto')
    print('CONNECTION Subscribed')
    time.sleep(10)
    conn.disconnect()
    return

I have updated my code after doing some basic research of how we can connect to different accounts:-

Response:
{
  "errorMessage": "module initialization error"
}

Request ID:
"9d810868-f165-11e8-b722-a38a441089b2"

Function Logs:
START RequestId: 9d810868-f165-11e8-b722-a38a441089b2 Version: $LATEST
module initialization error: name 'sts_response' is not defined

END RequestId: 9d810868-f165-11e8-b722-a38a441089b2
REPORT RequestId: 9d810868-f165-11e8-b722-a38a441089b2  Duration: 225.12 ms Billed Duration: 300 ms     Memory Size: 128 MB Max Memory Used: 30 MB  
module initialization error
name 'sts_response' is not defined

0条回答
登录 后发表回答