我目前正在尝试通过sam local invoke
命令在本地调用lambda函数,但是我通过GetObject操作不断收到InvalidToken错误。
我尝试过的事情:
ap-northeast-2
区域上进行所有操作,因此我仔细检查了一下
我的配置文件.aws
文件夹设置为相同的区域。--region ap-northeast-2
标志,但它给出了相同的错误。aws configure
),但是没有运气。还有其他我可能会忘记的事情吗? 以下是代码和日志输出。在此先感谢:)
# imports omitted
logger.info('Starting...')
s3 = boto3.client('s3')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
session = boto3.Session()
credentials = session.get_frozen_credentials()
print(credentials.access_key, credentials.secret_key, credentials.token)
def load_model(): # handler function
logger.info('Loading model from S3')
obj = s3.get_object(Bucket=MODEL_BUCKET, Key=MODEL_KEY )
# obj = s3.Object(bucket_name='ml-project-paul-kang', key='fastai-models/lesson1/model.tar.gz')
logger.info('Model loading complete')
bytestream = io.BytesIO(obj['Body'].read()) # further code omitted
这是我运行sam local invoke PyTorchFunction -n env.json -e event.json
后得到的结果:
Invoking app.lambda_handler (python3.6)
arn:aws:lambda:ap-northeast-2:<ID>:layer:pytorch-p36:1 is already cached. Skipping download
Requested to skip pulling images ...
[INFO] 2020-08-22T08:18:22.685Z Starting...
<CURRENT_USER_ACCESS_KEY> <CURRENT_USER_SECRET_KEY> (null)
[INFO] 2020-08-22T08:18:22.685Z Model Bucket is ml-project
[INFO] 2020-08-22T08:18:22.685Z Model Prefix is fastai-models/lesson1/model.tar.gz
[INFO] 2020-08-22T08:18:22.686Z Loading model from S3
module initialization error: An error occurred (InvalidToken) when calling the GetObject operation: The provided token is malformed or otherwise invalid.
答案 0 :(得分:1)
我认为您的s3存储桶不在ap-northeast-2
区域中。您可以在s3控制台上进行检查。如果不是,则需要通过以下代码传递区域。
s3 = boto3.client('s3', region_name='ap-northeast-2')