Using SecretManager in AWS Glue - isgaur/AWS-BigData-Solutions GitHub Wiki
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
import boto3
import base64
from botocore.exceptions import ClientError
secret_name = "test/dev/beta"
region_name = "us-east-1"
# Create a Secrets Manager client
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name="us-east-1"
)
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
print "hello",get_secret_value_response
if 'SecretString' in get_secret_value_response:
secret = get_secret_value_response['SecretString']
print "hello2", secret
else:
decoded_binary_secret = base64.b64decode(get_secret_value_response['SecretBinary'])
print "hello3", decoded_binary_secret
## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)
job.commit()