从Lambda连接到ASW Cognito时超时



我已经将Django应用程序部署到AWS Lambda,并将Cognito作为用户数据库。

为了创建用户,我使用在Cognito中创建用户的管理命令:

client = boto3.client(
'cognito-idp',
aws_access_key_id=settings.AMAZON_ACCESS_KEY_ID,
aws_secret_access_key=settings.AMAZON_SECRET_ACCESS_KEY,
region_name=settings.AWS_DEFAULT_REGION
)
print('Registering...')
print(f'ClientId={settings.COGNITO_AUDIENCE}')
register_response = client.sign_up(
ClientId=settings.COGNITO_AUDIENCE,
Username=user.email,
Password=password,
UserAttributes=[
{
'Name': 'custom:role',
'Value': user.role
},
{
'Name': 'email',
'Value': user.email
},
{
'Name': 'name',
'Value': user.name
},
]
)

当我在本地运行此代码时,一切都正常,用户正在创建。但是当我每次超时时都从lambda运行这个命令。

以下是lambda:的日志

Registering...
ClientId=************************
[DEBUG] 2020-05-04T15:22:28.620Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Event before-parameter-build.cognito-identity-provider.SignUp: calling handler <function generate_idempotent_uuid at 0x7f0d9a9583b0>
[DEBUG] 2020-05-04T15:22:28.621Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Event before-call.cognito-identity-provider.SignUp: calling handler <function inject_api_version_header_if_needed at 0x7f0d9a95ae60>
[DEBUG] 2020-05-04T15:22:28.621Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Making request for OperationModel(name=SignUp) with params: {'url_path': '/', 'query_string': '', 'method': 'POST', 'headers': {'X-Amz-Target': 'AWSCognitoIdentityProviderService.SignUp', 'Content-Type': 'application/x-amz-json-1.1', 'User-Agent': 'Boto3/1.12.22 Python/3.7.7 Linux/4.14.165-102.205.amzn2.x86_64 exec-env/AWS_Lambda_python3.7 Botocore/1.15.22'}, 'body': b'{"ClientId": "**********************", "Username": "test@gmail.com", "Password": "123123123", "UserAttributes": [{"Name": "custom:role", "Value": "owner"}, {"Name": "email", "Value": "test@gmail.com"}, {"Name": "name", "Value": ""}]}', 'url': 'https://cognito-idp.ap-southeast-1.amazonaws.com/', 'context': {'client_region': 'ap-southeast-1', 'client_config': <botocore.config.Config object at 0x7f0d959e2d90>, 'has_streaming_input': False, 'auth_type': 'none'}}
[DEBUG] 2020-05-04T15:22:28.621Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Event request-created.cognito-identity-provider.SignUp: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f0d959e2d50>>
[DEBUG] 2020-05-04T15:22:28.621Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Event choose-signer.cognito-identity-provider.SignUp: calling handler <function set_operation_specific_signer at 0x7f0d9a9558c0>
[DEBUG] 2020-05-04T15:22:28.621Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://cognito-idp.ap-southeast-1.amazonaws.com/, headers={'X-Amz-Target': b'AWSCognitoIdentityProviderService.SignUp', 'Content-Type': b'application/x-amz-json-1.1', 'User-Agent': b'Boto3/1.12.22 Python/3.7.7 Linux/4.14.165-102.205.amzn2.x86_64 exec-env/AWS_Lambda_python3.7 Botocore/1.15.22', 'Content-Length': '257'}>
[DEBUG] 2020-05-04T15:22:28.622Z    b65c34a0-9338-4ae5-a49f-4dc287bc4a60    Starting new HTTPS connection (1): cognito-idp.ap-southeast-1.amazonaws.com:443
END RequestId: b65c34a0-9338-4ae5-a49f-4dc287bc4a60
REPORT RequestId: b65c34a0-9338-4ae5-a49f-4dc287bc4a60  Duration: 30030.28 ms   Billed Duration: 30000 ms   Memory Size: 512 MB Max Memory Used: 148 MB Init Duration: 546.39 ms

它可能是什么?

请在lambda设置中仔细检查分配给执行的秒数。请将时间增加到10-15秒。

更新时间:请阅读这篇博文。https://www.alexdebrie.com/posts/aws-lambda-vpc/

相关内容

  • 没有找到相关文章

最新更新