-
Make an account on PyPI
-
Make sure you have
twine
andwheel
installed in yourvenv
:pip install twine wheel
-
Make sure you have your
~/.pypirc
file that looks like this:
# Strip out the unicode keys from a Python 2 dictionary (also includes nested Lists, Dicts, and Sets): | |
def py2_strip_unicode_keys(blob): | |
"""For Python 2 Only -- this will convert unicode keys in nested dictionaries to standard strings.""" | |
if type(blob) == unicode: | |
return str(blob) | |
elif type(blob) == dict: | |
for key in list(blob.keys()): | |
value = blob.pop(key) | |
blob[str(key)] = py2_strip_unicode_keys(value) |
import pytest | |
import moto | |
from mock import mock, patch | |
from moto import mock_lambda | |
@pytest.fixture(scope='function') | |
def aws_credentials(): | |
"""Mocked AWS Credentials for moto.""" |
{ | |
"Records": [ | |
{ | |
"EventSource": "aws:sns", | |
"EventVersion": "1.0", | |
"EventSubscriptionArn": "arn:aws:sns:REGION:ACCOUNT:TOPICNAME:SOME-ID", | |
"Sns": { | |
"Type": "Notification", | |
"MessageId": "SOME-ID", | |
"TopicArn": "arn:aws:sns:REGION:ACCOUNT:TOPICNAME", |
import io | |
import os | |
from zipfile import ZipFile | |
import pytest | |
@pytest.fixture | |
def archive(): | |
archive_file = io.BytesIO() |
def snake_to_camels(data: object) -> object: | |
"""Function that recursively converts snake_case to camelCase in a dict.""" | |
if isinstance(data, dict): | |
data_copy = dict(data) | |
for key, value in data.items(): | |
# Send the value back: | |
new_value = snake_to_camels(value) | |
# In case the key isn't a string (like an Int): |
Documented here: https://aws.amazon.com/blogs/security/how-to-restrict-amazon-s3-bucket-access-to-a-specific-iam-role/ | |
Yes, it's really shitty. | |
Example Policy to ONLY allow specific IAM Roles access to the objects (denies all the other roles access to the objects): | |
{ | |
"Version": "2008-10-17", | |
"Statement": [ | |
{ |
# from botocore.session import Session | |
# from botocore.credentials import AssumeRoleProvider, CredentialResolver, AssumeRoleCredentialFetcher, \ | |
# DeferredRefreshableCredentials, _local_now | |
# """ | |
# # Where much of this is referenced: | |
# https://github.com/aws/aws-cli/blob/f4ea4b682e792eb474e9e3c3a74b16ab34ba95c0/tests/integration/test_cli.py | |
# https://github.com/boto/botocore/blob/fd6aac245b24dbdbfc6e0c5ecd7530cfe4346794/botocore/session.py | |
# https://github.com/boto/botocore/blob/fd6aac245b24dbdbfc6e0c5ecd7530cfe4346794/botocore/credentials.py | |
# """ |
from datetime import datetime | |
# Prints a string that looks like: 2017-08-30T21:19:30 (this is a good standard ISO format) | |
current_time = datetime.utcnow().replace(tzinfo=None, microsecond=0).isoformat() | |
print(current_time) | |
# 2019-02-04T19:44:04 | |
# To read in a string like above | |
date_obj = datetime.strptime(current_time, "%Y-%m-%dT%H:%M:%S") |
import boto3 | |
BUCKET = "LOLSOMEBUCKET" | |
KEY = "LOL/SOME/KEY" | |
client = boto3.client("s3") | |
result = client.get_object(Bucket=BUCKET, Key=KEY) | |
compressed = False |