Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
wrapper around s3cmd
#!/usr/bin/env python
import sys
import subprocess
def get_profile_credentials(profile_name):
# stolen from
from configparser import ConfigParser
from configparser import ParsingError
from configparser import NoOptionError
from configparser import NoSectionError
from os import path
config = ConfigParser()[path.join(path.expanduser("~"),'.aws/credentials')])
aws_access_key_id = config.get(profile_name, 'aws_access_key_id')
aws_secret_access_key = config.get(profile_name, 'aws_secret_access_key')
aws_session_token = config.get(profile_name, 'aws_session_token')
except ParsingError:
print('Error parsing config file')
except (NoSectionError, NoOptionError):
aws_access_key_id = config.get('default', 'aws_access_key_id')
aws_secret_access_key = config.get('default', 'aws_secret_access_key')
aws_session_token = config.get('default', 'aws_session_token')
except (NoSectionError, NoOptionError):
print('Unable to find valid AWS credentials')
return aws_access_key_id, aws_secret_access_key, aws_session_token
if __name__=='__main__':
AWS Access Key
AWS Secret Key
profile, cmd_args = sys.argv[1], sys.argv[2:]
aws_args = get_profile_credentials(profile)
cmd = [
] + cmd_args

This comment has been minimized.

Copy link
Owner Author

squarepegsys commented Sep 23, 2019

Usage: <profile_name> <s3cmd command>

So if you are putting fancy-file into s3://my-fancy-bucket/some-folder using your development AWS profile, it's: development put fancy-file s3://my-fancy-bucket/some-folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.