Created
February 21, 2020 23:58
-
-
Save georgerussellpruitt/cb9efa0cb8c9fc6a615bf2011cbd9b8d to your computer and use it in GitHub Desktop.
s3 flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE="test.csv" | |
if test -f "/path/to/$FILE"; then | |
aws s3 cp $FILE s3://my-aws-bucket-arn/ | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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