Created
September 2, 2018 09:14
-
-
Save kojiisd/c0432c3b7a8940ecdda3af48981e8db3 to your computer and use it in GitHub Desktop.
AWS LambdaでCognitoユーザ一覧を取得 ref: https://qiita.com/kojiisd/items/690b5952835823ac1be1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from datetime import datetime | |
import os | |
import boto3 | |
cognito_client = boto3.client('cognito-idp') | |
def list_users(event, context): | |
if 'UserPoolId' not in event: | |
raise KeyError("UserPoolId does not exist.") | |
response = cognito_client.list_users( | |
UserPoolId = event['UserPoolId'] | |
) | |
return json.dumps(response, default=support_datetime_default) | |
def support_datetime_default(obj): | |
if isinstance(obj, datetime): | |
return obj.isoformat() | |
raise TypeError(repr(obj) + " is not JSON serializable") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: lambda-cognito-user-manager | |
provider: | |
name: aws | |
runtime: python3.6 | |
region: us-east-1 | |
iamRoleStatements: | |
- Effect: "Allow" | |
Action: | |
- "cognito-idp:ListUsers" | |
Resource: "arn:aws:cognito-idp:*" | |
functions: | |
cognito-manager: | |
handler: handler.list_users | |
memorySize: 128 | |
timeout: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"UserPoolId": "us-east-1_XXXXXXXXXXX" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Users": [ | |
{ | |
"Username": "admin", | |
"Attributes": [ | |
{ | |
"Name": "sub", | |
"Value": "00000000-0000-0000-XXXX-XXXXXXXXXXXX" | |
}, | |
{ | |
"Name": "email_verified", | |
"Value": "false" | |
}, | |
{ | |
"Name": "email", | |
"Value": "xxxxxx@xxx.com" | |
} | |
], | |
"UserCreateDate": "2018-09-01T07:07:28.497000+00:00", | |
"UserLastModifiedDate": "2018-09-01T07:09:20.934000+00:00", | |
"Enabled": true, | |
"UserStatus": "CONFIRMED" | |
} | |
], | |
"ResponseMetadata": { | |
"RequestId": "XXXXXXXX-xxxx-xxxx-0000-XXXXXXXXXX", | |
"HTTPStatusCode": 200, | |
"HTTPHeaders": { | |
"date": "Sun, 02 Sep 2018 08:37:00 GMT", | |
"content-type": "application/x-amz-json-1.1", | |
"content-length": "312", | |
"connection": "keep-alive", | |
"x-amzn-requestid": "XXXXXXXX-xxxx-xxxx-0000-XXXXXXXXXX" | |
}, | |
"RetryAttempts": 0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment