Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download step from csds #4

Merged
merged 12 commits into from
Jun 9, 2022
Merged

Conversation

billfreeman44
Copy link
Member

No description provided.

@billfreeman44 billfreeman44 requested a review from razor-x June 7, 2022 18:49
@razor-x
Copy link
Member

razor-x commented Jun 8, 2022

@billfreeman44 There are not tested, but should be all we need to setup a basic bucket config.

days_to_keep_data_on_s3 = 30
account_id = boto3.client("sts").get_caller_identity().get("Account")
bucket_name = "-".join([account_id, "pureskillgg", "dataset"])
bucket_region = boto3.session.Session().region_name

client = boto3.client("s3")

client.create_bucket(
    Bucket=bucket_name,
    ACL="private",
    CreateBucketConfiguration={"LocationConstraint": bucket_region},
)

client.put_bucket_policy(
    Bucket=bucket_name,
    Policy=json.dumps(
        {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Principal": {"Service": "dataexchange.amazonaws.com"},
                    "Action": ["s3:PutObject", "s3:PutObjectAcl"],
                    "Resource": f"arn:aws:s3:::{bucket_name}/*",
                    "Condition": {"StringEquals": {"aws:SourceAccount": account_id}},
                }
            ],
        }
    ),
)

client.put_bucket_lifecycle_configuration(
    Bucket=bucket_name,
    LifecycleConfiguration={
        "Rules": [
            {
                "Expiration": {
                    "Days": days_to_keep_data_on_s3,
                },
                "Status": "Enabled",
            },
        ],
    },
)

@razor-x
Copy link
Member

razor-x commented Jun 8, 2022

We should add a check at the top of the cell incase the bucket exists. There are three cases for this call

client.head_bucket(
  Bucket='string',
  ExpectedBucketOwner=account_id
)
  1. Bucket exists and is owned by account_id so no error and we can continue without creating the bucket / acl / lifecycle (assume it's good to go).
  2. Bucket exists and is NOT owned by account_id, so they need a different bucket name or are on the wrong account.
  3. Bucket does not exist so we can go ahead and create it.

@billfreeman44 billfreeman44 requested a review from razor-x June 9, 2022 00:16
@billfreeman44
Copy link
Member Author

Should be good to go @razor-x

Copy link
Member

@razor-x razor-x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll check it one more time after these updates, but I have to head off for now. I recommend batching the suggestions instead of single commits!

@billfreeman44 billfreeman44 merged commit f92ee96 into master Jun 9, 2022
@billfreeman44 billfreeman44 deleted the add-download-step-from-csds branch June 9, 2022 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants