// json 파일을 읽어와서 json 형태로 출력 var theObject = await s3.getObject(params).promise(); const data = JSON.parse(theObject.Body); console.log(data); // console.log(theObject.Body.toString('utf8')); // 보기 예쁜 형태로
// S3에서 이벤트가 발생할 때마다 로그에 찍어줄 값.
try { const { ContentType } = await s3.getObject(params).promise(); console.log('CONTENT TYPE:', ContentType); console.log('********** Event generated by S3 ************* '); return ContentType; } catch (err) { console.log(err); const message = `Error getting object ${key} from bucket ${bucket}. Make sure they exist and your bucket is in the same region as this function.`; console.log(message); throw new Error(message); } };
3. 람다의 테스트에서 awsRegion, bucket-name, arn, key를 바꾸어주어야 정상 테스팅됨.
람다 테스트
"awsRegion": “ap-northeast-2",
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"name": "jane-bkt”,
"ownerIdentity": {
"principalId": "EXAMPLE"
},
"arn": "arn:aws:s3:::jane-bkt"
},
"object": {
"key": "s3test.json",
"size": 1024,
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901"
}
4. 테스팅 결과
1) json 파일이 예쁘게 나온다.
2) S3의 해당 버킷에 새로운 파일을 업로드할 경우, 람다가 실행되어 Cloudwatch에서 로그를 확인할 수도 있다.