""" Package and upload lambda ========================= This uses the following environment variables to get the API key pairs for the different stages: dev stage: DEV_AWS_ACCESS_KEY_ID DEV_AWS_SECRET_ACCESS_KEY prod stage: PROD_AWS_ACCESS_KEY_ID PROD_AWS_SECRET_ACCESS_KEY """ import os import os.path import boto3 lambda_function = 'FTMicrositeContactForm' while True: stage = raw_input('Specify deploy stage: "dev" or "prod": ') if stage == 'dev' or stage == 'prod': break env_access_key = '{stage}_AWS_ACCESS_KEY_ID'.format(stage=stage.upper()) env_secret_key = '{stage}_AWS_SECRET_ACCESS_KEY'.format(stage=stage.upper()) zip_file = os.path.join( 'lambda_builds', 'lambda.{stage}.zip'.format(stage=stage)) api_key_pair = { 'aws_access_key_id': os.environ.get(env_access_key), 'aws_secret_access_key': os.environ.get(env_secret_key)} fh = open(zip_file, 'rb') client = boto3.client('lambda', 'us-east-1', **api_key_pair) client.update_function_code(FunctionName=lambda_function, ZipFile=fh.read())