0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python3: Kinesis から Lambda に渡されたパラメーターを読む方法

Posted at

Lambda でトリガーを Kinesis に指定した時、パラメーターは base64 でエンコードされて渡されます。その値を読む Lamba のプログラムです。

lambda_monitor.py
# -*- coding: utf-8 -*-
#
#	lambda_monitor.py
#
#				   Sep/21/2021
#
# --------------------------------------------------------------------
import sys
import base64
import json

# --------------------------------------------------------------------
def lambda_handler(event, context):
	sys.stderr.write("*** lambda_handler *** start ***\n")
	print("Received event: " + json.dumps(event, indent=2))
	sys.stderr.write("*** lambda_handler *** bbb ***\n")
	data_in = event["Records"][0]["kinesis"]["data"]
	decoded = base64.b64decode(data_in)
	str_out = decoded.decode()
	print(str_out)
	sys.stderr.write("*** lambda_handler *** end ***\n")
#
	return "OK"
# --------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?