Has anyone found a way to hide boto3 credentials in a python script that gets called from AWS Glue?

Right now I have my key and access_key embedded within my script, and we all know that’s not good practice…


Related discussions:

I haven’t used Glue yet or really looked in to it… but is there no Role’s available in Glue? Can you not create a role with the permissions and then give you Glue (function?) the role?

Not that I can find. I know of the IAM user, but it doesn’t seem applicable (that I can see anyway) to my Glue job. I just need Glue to automate running a python script that connects to one source (for me to stream data) then I use boto3 to load into S3 target buckets.

It’s the boto3 authentication that I’m having a hard time. When I run boto3 using python on a scripting server, I just create a profile file in my .aws directory with my credentials encrypted and hidden there, but I’m confused as to how to do this using Glue to launch my scripts.

Is Lambda not an option? I am not quite sure why you are using Glue when you are just moving content from one place in to S3.

If you do need to ETL with Glue, you can always trigger it after it is in S3 via Glue triggers

Damn good question! I will ask my Data Architect. He is the one who’s tasked me to write a python script to take a bunch of tar.gz files, open them and move them to the appropriate buckets based on key words and dates, then challenged me to find a way to automate without us using a scripting server…

Thanks for the chat.

So you can trigger a lambda function to do this task for sure, just a matter of how you trigger it.

In theory, you can:

  • Script a server to upload your tar.gz files to an S3 bucket
  • Have Lambda triggered on new object in that S3 bucket
  • Lambda picks up the files (via a role) and unzips using boto3
  • Lambda then places the files in a different S3 bucket that has a new trigger to call Glue.
  • Glue picks up the new event and does the ETL

EDIT: I don’t know pricing on Glue, but Lambda in this case would be free, or extremely cheap. You would of course pay for the S3 storage, and anything Glue is doing, but the Lambda processes would most likely fall in to the free tier.

Can you use parameter store?

Or programatically go get a temp access key (based on the executing role)?

Glue uses a roles for everything. The boto3 library will just pull in the creds automatically.

http://docs.aws.amazon.com/glue/latest/dg/create-an-iam-role.html

Thank you!

I am dumbfounded I didn’t think of just not adding in my credentials and seeing how boto3 would react. It works like a charm just using

session = boto3.Session(region_name='my_region_name')

Thanks again!

This is the right answer. Don’t over think it! AWS likely already has a solution.

This is a good response. Storing encrypted credentials via kms in parameter store or dynamodb is best practice. Then tell your lambda or script to get them, decrypt them, and only store them in ram. This circumvents hard coding creds.

Replying to mark this as something to try - hadn’t thought of Lambda to do this type of work

Someone else did mention that Glue has the role function so this is not needed, but you could use Lambda to do this sort of processing to pick up files > process > put somewhere else.

right now, I use AWS CLI calls on an EC2 instance to read from one S3 bucket, process, then write findings to other S3 bucket, and it’s a bit pricey to do that :-/

I have a love affair with Parameter Store. It’s perfect for that sort of thing