Skip to content

Commit

Permalink
Merge pull request aws-samples#4 from nicka/master
Browse files Browse the repository at this point in the history
Add support for a sync Prefix, copying of Metadata and Tags
  • Loading branch information
glez-aws authored Jul 4, 2017
2 parents 2086ef2 + ebe7cb3 commit 02588b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
fabfile_config.py
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,25 @@ Start the Amazon Step Functions console in your chosen region and start a new ex
"destination": "your-destination-bucket-name"
}
```


Optionally sync based on a prefix:

```json
{
"source": "...",
"destination": "...",
"prefix": "/images/"
}
```

## How to uninstall

This assumes that you're still working from the sync-buckets-state-machine that you installed into in the steps above.

> fab delete # Delete the CloudFormation stack and its resources.
> deactivate # Deactivate the Python virtual environment
> cd ../..; /bin/rm -rf env # Clean up.

## Files/directories

* *lambda_functions*: All AWS Lambda functions are stored here. They contain YAML front matter with their configuration.
Expand All @@ -76,9 +86,7 @@ This assumes that you're still working from the sync-buckets-state-machine that
a timestamp suffix to distinguish different state machine versions from each other.
* *README*: This file.
* *requirements.txt*: Python requirements for this project.

## Feedback

Please send feedback, suggestions, etc. to glez@amazon.de (Constantin Gonzalez)


4 changes: 3 additions & 1 deletion lambda_functions/copy_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def copy_object(self, key):
'Key': key
},
Bucket=self.destination,
Key=key
Key=key,
MetadataDirective='COPY',
TaggingDirective='COPY'
)

def run(self):
Expand Down
5 changes: 4 additions & 1 deletion lambda_functions/list_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
MAX_DATA_SIZE = 32000 # Max. result size: https://docs.aws.amazon.com/step-functions/latest/dg/service-limits.html
SAFETY_MARGIN = 10.0 # Percent
MAX_RESULT_LENGTH = int(MAX_DATA_SIZE * (1.0 - (SAFETY_MARGIN / 100.0)))
PREFIX = '' # Copy objects based on a provided prefix e.g. '/images/'


# Globals
Expand All @@ -61,10 +62,12 @@ def handler(event, context):

token = event.get('listResult', {}).get('token', '')
max_keys = event.get('maxKeys', MAX_KEYS)
prefix = event.get('prefix', PREFIX)

args = {
'Bucket': bucket,
'MaxKeys': max_keys
'MaxKeys': max_keys,
'Prefix': prefix
}

result = {}
Expand Down

0 comments on commit 02588b9

Please sign in to comment.