AWS Glue JOB to get secret value from secretmanager

784 Views Asked by At

I'm working on the AWS glue job, can someone please help me to give me a script in AWS Glue Job Spark that would retrieve my secrets from secret manager. Help is appreciated.

1

There are 1 best solutions below

0
On

It is fairly simple (if you have all of the required IAM permissions) using boto3 and get_secret_value() function.

sm_client = boto3.client('secretsmanager')
response = sm_client.get_secret_value(
    SecretId=<your_secret_id>
)

If the value is a string, you can extract it like this:

value = secret_value_response['SecretString']

If it is a binary value:

secret_value_response['SecretBinary']

Additionally, if the secret has multiple versions of the secret, you have to use VersionId and/or VersionStage as explained in the linked documentation.