IAMロールを作成する

IAMロールを作成する
ポリシーには以下二つの権限をつける。
-AWSLambdaBasicExecutionRole
-AmazonS3FullAccess

'use strict';

const aws = require('aws-sdk');
const s3 = new aws.S3();

exports.handler = function(event, context){
	console.log('Received event:', JSON.stringify(event, null, 2));

	const uploadBucket = event.Records[0].s3.bucket.name;
	const key = event.Records[0].s3.object.key;

	const params = {
		Bucket: uploadBucket,
		Key: key
	};
	s3.getObject(params, function(err, data){
		if(err){
			console.log(err, err.stack);
			context.done(err, err.stack);
		} else {
			console.log('data: ', data);

			const copyBucket = 'sample-copy-bucket';
			const params = {
				Bucket: copyBucket,
				Key: key,
				Body: data.Body
			};
			s3.putObject(params, function(err, data){
				if(err){
					console.log(err, err.stack);
					context.done(err, err.stack);
				} else {
					console.log('data: ', data);
					context.suceed('complete!');
				}
			});
		}
	});
};