Skip to content

Instantly share code, notes, and snippets.

@rhoboro
Created October 25, 2015 11:40
Show Gist options
  • Save rhoboro/bc7fd37f2022f052e119 to your computer and use it in GitHub Desktop.
Save rhoboro/bc7fd37f2022f052e119 to your computer and use it in GitHub Desktop.
import json
import os.path
import sys
import os
# boto3のバージョンが古いためカレントディレクトリにインストールしたboto3を利用する
# pip install -t boto3 .
root = os.environ["LAMBDA_TASK_ROOT"]
sys.path.insert(0, root)
import boto3
from boto3.session import Session
AWS_ACCESS_KEY_ID = ""
AWS_SECRET_ACCESS_KEY = ""
AWS_DEFAULT_REGION = "ap-northeast-1"
accesskey = os.environ.get(AWS_ACCESS_KEY_ID)
secretkey = os.environ.get(AWS_SECRET_ACCESS_KEY)
region = os.environ.get(AWS_DEFAULT_REGION)
session = Session(aws_access_key_id=accesskey,
aws_secret_access_key=secretkey,
region_name=region)
def get_credential(email):
print("boto3" + boto3.__version__)
client = boto3.client('cognito-identity')
# デフォルトのboto3(1.3.1)を利用するとバージョンが古いため
# IdentityPoolIdがバリデーションチェックに引っかかる
response = client.get_open_id_token_for_developer_identity(
IdentityPoolId='ap-northeast-1:XXX',
Logins={
'AuthenticationProvider': email
},
TokenDuration=123
)
return response
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Authentication')
response = table.get_item(Key={"email": event["email"]})
if "Item" in response:
user = response["Item"]
if user["pass"] == event["pass"]:
credential = get_credential(event["email"])
return json.dumps({"result": "success", "credential": credential})
return json.dumps({"result": "failure"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment