python-3.x - 如何在 python3.6 中的 AWS Lambda 中存储和访问 microsoft office365 帐户令牌
问题描述
解决方案
我遇到了同样的问题。lambda 文件系统是临时的,因此每次运行该函数时都需要执行 auenticate 过程,并且 o365 库将要求提供 url。因此,请尝试将您的令牌 (o365_token.txt) 保存在 S3 中,而不是在 lambda 文件系统中获取它并使用此令牌进行身份验证。我希望这段代码可以帮助你:
import boto3
bucket_name = 'bucket_name'
# replace with your bucket name
filename_token = 'o365_token.txt'
# replace with your AWS credentials
s3 = boto3.resource('s3',aws_access_key_id='xxxx', aws_secret_access_key='xxxx')
# Read the token in S3 and save to /tmp directory in Lambda
s3.Bucket(bucket_name).download_file(filename_token, f'/tmp/{filename_token}')
# Read the token in /tmp directory
token_backend = FileSystemTokenBackend(token_path='/tmp',
token_filename=filename_token)
# Your azure credentials
credentials = ('xxxx', 'xxxx')
account = Account(credentials,token_backend=token_backend)
# Then do the normal authentication process and include the refresh token command
if not account.is_authenticated:
account.authenticate()
account.connection.refresh_token()
推荐阅读
- javascript - Redux 状态不会在 firebase auth onAuthStateChanged 回调中更新
- python - 如何在 Windows 中自动吞噬 Python 的 argparse 路径输入?
- synonym - Elastic Search 中由其他字段控制的同一字段的多个同义词列表
- nearprotocol - 近部署与近开发部署的用例差异
- javascript - 如何在 DevExtream 的散点图中和单独的数组中获取重叠点?
- docker - 将 Linux 服务器迁移到 docker 的最简单方法(apache2 和 yii-framework-1.1.10 + 远程 DB pgsql)
- python - 有没有 python 异步文件处理程序?
- android - 未生成 Crashlytics 映射文件
- rest - 在相同的状态码中有不同的响应格式是一个好的 RESTFUL API 吗?
- caching - 这种 CDN/缓存模式的名称是什么,最省力的解决方案是什么?