[英]AWS Python: can't get data from a dynamodb in a lambda with get_item
[英]get_item dynamodb with if else condition if item has a match
def main():
alias = "jen"
ddb = boto3.client("dynamodb")
get_ddb_item = ddb.get_item(TableName="testtable", Key={"employee": {"S": alias}})
item = get_ddb_item["Item"]
print(item)
if item == alias:
print(f"{alias} is an employee")
else:
print(f"{alias} is not an active employee")
testtable
上唯一的内容是PK: employee item: "jen"
I am expecting an out put of jen is an employee
这是我上面的代码,它给了我相反的jen is not an active employee
获得预期的 output 的正确方法是什么?
你得到这个是因为item != 'jen'
if item['employee']['S'] == alias:
print(f"{alias} is an employee")
else:
print(f"{alias} is not an active employee")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.