尝试为 AWS Lamdba 函数运行 python 测试。测试代码将不会运行并输出此错误
Traceback (most recent call last):
line 4, in <module>
File "/home/ordep81/Documents/cloud-challenge/Lambda/app.py", line 7, in <module>
region_name = os.environ['REGION_NAME']
File "/usr/lib/python3.8/os.py", line 673, in __getitem__
raise KeyError(key) from None
这是初始化变量 app.py 的代码:
import boto3
import json
import os
# create the client outside of the handler
region_name = os.environ['REGION_NAME']
dynamo = boto3.client('dynamodb')
table_name = os.environ['TABLE_NAME']
运行测试 test_app.py 的代码
import boto3
import os
import unittest
from app import lambda_handler
from moto import mock_lambda