Skip to content

Instantly share code, notes, and snippets.

@georgerussellpruitt
Created February 21, 2020 23:58
Show Gist options
  • Save georgerussellpruitt/cb9efa0cb8c9fc6a615bf2011cbd9b8d to your computer and use it in GitHub Desktop.
Save georgerussellpruitt/cb9efa0cb8c9fc6a615bf2011cbd9b8d to your computer and use it in GitHub Desktop.
s3 flow
#!/bin/bash
FILE="test.csv"
if test -f "/path/to/$FILE"; then
aws s3 cp $FILE s3://my-aws-bucket-arn/
fi
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
exports.handler = async(event) => {
var bucket = event.Records[0].s3.bucket.name;
var output = {};
const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
const params = {
Bucket: bucket,
Key: key
};
s3.getObject(params, function(err, data) {
if (err){
console.log(err, err.stack); // an error occurred
return err.stack;
} else {
var copyParams = {
Bucket: "destinationbucket",
CopySource: "/sourcebucket/HappyFacejpg",
Key: "HappyFaceCopyjpg"
};
s3.copyObject(copyParams, function(err, data) {
if (err){
console.log(err, err.stack);// an error occurred
return err.stack;
} else {
console.log(data);// successful response
}
const response = {
statusCode: 200,
body: data,
};
return response;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment