Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

その接続先情報はどこに

aibou
September 09, 2016

 その接続先情報はどこに

Gunosy Beer Bash #8 Serverless Architecture Talksで発表した資料です
http://gunosy-beer.connpass.com/event/38949/

aibou

September 09, 2016
Tweet

More Decks by aibou

Other Decks in Programming

Transcript

  1. ͓·͑ͩΕ • @aibou (͸·͡ Γΐ͏͚͢) • ʮ͍͋΅͏͞Μͬͯຊ໊ͳΜͰ͚ͨͬ͠ʁʯ • GunosyαʔϏεͷΠϯϑϥશൠ୲౰(AWSྺ1೥ͪΐ͍) •

    Java(Spring Boot), Ruby, Chef • झຯɿεϙʔπ؍ઓ ⚾Ϟʔλʔεϙʔπ • ࡢ೔DAZNొ࿥͠·ͨ͠ɻڵຯ͋Δਓ͸࠙਌ձͰͥͻ • Ԍ্ྺ͋Γ
  2. ConfigϑΝΠϧͷαϯϓϧ { "DATABASES": { "master": { "HOST": "", "PORT": "",

    "NAME": "", "USER": "", "PASSWORD": "" } } } γϯϓϧʂ ΋ͪΖΜ%#Ҏ֎ͷઃఆ΋هࡌͯͨ͠Γ͠·͢
  3. Lambda্Ͱͷσίʔυ ʢPythonʣ kms = boto3.client('kms') with open(encrypted_json_path) as f: _settings

    = json.loads( kms.decrypt(CiphertextBlob=f.read())['Plaintext'] ) DATABASES = _settings.get("DATABASES") or {} # DATABASES['master']['HOST'] # DATABASES['master']['USER'] IPHF@@JOJU@@QZʹॻ͍͓͚ͯ͹ JNQPSUIPHFͰ࢖͑Δͷ΋˓
  4. Description͔Βऔಘ ʢPythonʣ import boto3 import json def lambda_handler(event, context): configuration

    = boto3.client('lambda').get_function_configuration( FunctionName=context.function_name ) json_conf = json.loads(configuration['Description']) return json_conf['name']