Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

lambda to redshift python

import json
import urllib.parse
import boto3
import botocore.session as bc

print('Loading function')

s3 = boto3.client('s3')


def lambda_handler(event, context):
    print("Entered lambda_handler")

    secret_name='redshift' ## HERE add the secret name created.
    session = boto3.session.Session()
    region = session.region_name
    
    client = session.client(
            service_name='secretsmanager',
            region_name=region
        )
    
    get_secret_value_response = client.get_secret_value(
            SecretId=secret_name
        )
    secret_arn=get_secret_value_response['ARN']
    
    secret = get_secret_value_response['SecretString']
    
    secret_json = json.loads(secret)
    
    cluster_id=secret_json['dbClusterIdentifier']
    
    
    bc_session = bc.get_session()
    
    session = boto3.Session(
            botocore_session=bc_session,
            region_name=region,
        )
    
    # Setup the client
    client_redshift = session.client("redshift-data")
    print("Data API client successfully loaded")
    
    query_str = "create table public.lambda_func (id int);"
                      
    print(query_str)
    
    res = client_redshift.execute_statement(Database= 'dev', SecretArn= secret_arn, Sql= query_str, ClusterIdentifier= cluster_id)
    id=res["Id"]
Comment

PREVIOUS NEXT
Code Example
Python :: downsample audio 
Python :: Python matplotlib multiple bars 
Python :: python restrict function parameter type 
Python :: how to calculate iqr in pandas 
Python :: penggunaan items di python 
Python :: how to avoind DeprecationWarning in python 
Python :: Demonstration of Python range() 
Python :: how to do alignment of fasta in biopython 
Python :: How to Preprocess for categorical data 
Python :: beautifulsoup - extracting link, text, and title within child div 
Python :: combination in python without itertools 
Python :: list average python recursion 
Python :: Examples of correct code for this rule with global declaration: 
Python :: installing blacksheep 
Python :: update table odoo13 
Python :: How do I pre-select specific values from a dynamically populated dropdown list for HTML form 
Python :: Determining the Data Type 
Python :: _tkinter.TclError: invalid command name ".!canvas" 
Python :: self.stdout.write django 
Python :: ring Copy Lists 
Python :: hacer un programa en python ingresar números enteros obtenga el segundo valor máximo 
Python :: ring create an application to ask the user about his/her name. 
Python :: size of variable 
Python :: convert python code to c++ online 
Python :: output of an intermediate layer 
Python :: seleniu get element value and store it in a variable - selenium remember user 
Python :: ROC plot for h2o package 
Python :: discord.py reply to message 
Python :: turtle meaning 
Python :: show all of a truncated dataframe jupyter" 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =