<aside> 💡 참고자료 공식문서

</aside>

Untitled

기능


이것은 AWS Athena 서비스로 쿼리를 날려 결과를 비동기, 동기적으로 JSON 형태로 깔끔히 받을 수 있다.

사전 설정사항


  1. IAM Role 설정 필요(Lambda, EC2 뭐든)
  2. aws-sdk conf 설정 필요(NodeJS 앱으로 구동시)
  3. AmazonAthenaFullAccess, AmazonS3FullAccess

설정사항


  1. 람다를 사용할 것이므로, 람다의 역할에 위에 사전 설정사항의 권한을 부여한다.
  2. 코드
"use strict";

const AthenaExpress = require("athena-express"),
	AWS = require("aws-sdk");

	/* AWS Credentials are not required here 
    /* Make sure the IAM Execution Role used by this Lambda 
    /* has the necessary permission to execute Athena queries 
    /* and store the result in Amazon S3 bucket
    /* See configuration section above under Setup for more info */

const athenaExpressConfig = {
	aws: AWS,
	db: "myapp_cf_access_logs_db",
	getStats: true
};
const athenaExpress = new AthenaExpress(athenaExpressConfig);

exports.handler = async event => {
	const sqlQuery = "SELECT * FROM myapp_cf_access_logs_db.combined limit 1";

	try {
		let results = await athenaExpress.query(sqlQuery);
		return results;
	} catch (error) {
		return error;
	}
};