aws-lambda
AWS 람다 (S3 포함)
수색…
소개
람다 개발자는 다른 AWS 리소스를 사용해야하는 문제를 처리합니다. 이 주제는 정적 파일 및 기타 구성을 저장하는 데 일반적으로 사용되는 S3 (Simple Storage Service)에 중점을 둡니다. 이 문서에서는 람다에서 AWS-SDK를 사용하고 람다에서 S3의 파일에 액세스하고 S3 이벤트가 시작되면 람다 함수를 트리거하는 것을 고려합니다
컨닝 지
자바 스크립트 용 AWS-SDK
Lambda는 aws-sdk ( https://aws.amazon.com/sdk-for-node-js/) 를 전역에 포함하므로이 노드 모듈을 zip에 업로드 할 필요가 없습니다.
const AWS = require('aws-sdk');
샘플 기능
module.exports.myFunction = (event, context, callback) => {
const response = {
statusCode: 200,
body: 'Hello Lambda!',
};
return callback(null, response);
};
S3 실행 중
const s3 = new AWS.S3 ();
Elasticache Redis와 함께 사용
//make sure redis node-module is added in zip
const redis = require('redis');
//the redis information should be stored in the environment, not hard coded
const redis_options = {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT
};
module.exports.myFunction = (event, context, callback) => {
try {
let client = redis.createClient(redis_options);
context.callbackWaitsForEmptyEventLoop = false;
client.on('connect', () => {
console.log('Connected:', client.connected);
});
client.on('end', () => {
console.log('Connection closed.');
});
client.on('ready', function () {
console.log('Connection ready.');
client.keys('*', (err, keys) => {
//always quit the redis client when no longer needed
//else the connection will be used up
client.quit();
const response = {
statusCode: 200,
body: keys,
};
return callback(null, response);
});
} catch (err) {
if (client) { client.quit();}
console.log('Error!: ' + err.message);
callback(err);
}
};
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow