0

나는 redis (amazon elasticcache에서)를 사용하는 AWS Lambda 함수를 작성하려고합니다. 문제 - 내가 redis에 연결할 수 없습니다. 나는 확실히 내가 추가 행이 말이 안 뭔가 레디 스 URL을 변경할 때AWS Lambda and Redis

 
15:33:41 
START RequestId: d8024ec2-7f36-11e6-996c-1bfcb60572c6 Version: $LATEST 
 
15:33:42 
2016-09-20T13:33:42.632Z d8024ec2-7f36-11e6-996c-1bfcb60572c6 before client initialization 
 
15:33:42 
2016-09-20T13:33:42.813Z d8024ec2-7f36-11e6-996c-1bfcb60572c6 after client initialization 
 
15:33:44 
END RequestId: d8024ec2-7f36-11e6-996c-1bfcb60572c6 
 
15:33:44 
REPORT RequestId: d8024ec2-7f36-11e6-996c-1bfcb60572c6 Duration: 3002.67 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 19 MB 
 
15:33:44 
2016-09-20T13:33:44.620Z d8024ec2-7f36-11e6-996c-1bfcb60572c6 Task timed out after 3.00 seconds 

: 나는 로그에서이 같은 내용이 결과로이

'use strict' 

function handler (data, context, cb) { 
    const redis = require("redis") 
    console.log('before client initialization') 
    const client = redis.createClient({ 
    url: 'redis://propper-url-cache.some.0001.euw1.cache.amazonaws.com:6379', 
    retry_strategy: function(options) { 
     console.log(options) 
     if (options.total_retry_time > 1000) { 
     throw new Error('can`t connect to redis') 
     } 
    } 
    }) 
    console.log('after client initialization') 

    client.on("error", function (err) { 
    console.log('in error') 
    cb({error: err}) 
    }); 

    client.get("counter", function (err, counter) { 
    console.log('counter', counter) 
    if(_.isNull(counter)) { 
     counter = 0 
    } 
    client.set('counter', counter + 1, function(err) { 
     console.log(err) 
     cb(null, {counter: counter}) 
    }) 
    }); 
} 

exports.handler = handler 

과 같은 코드를 사용

2016-09-20T13:29:42.953Z 48fcb071-7f36-11e6-bc52-c5ac58c12843 { attempt: 1, error: { [Error: Redis connection to some-url.euw1.cache.amazonaws.com:6379 failed - getaddrinfo ENOTFOUND some-url.euw1.cache.amazonaws.com some-url.euw1.cache.amazonaws.com:6379] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo', hostna 

아이디어가 있으십니까?

+0

람다 함수에 대해 VPC 액세스를 활성화 했습니까? –

+0

그래, 문제는 VPC 액세스에있었습니다. 감사. 내가 왜 다른 행동을하는 이유가 있니? – kharandziuk

+1

존재하지만 무언가에 액세스하려하지만 (부적절한 VPC 구성으로 인해) 네트워크 액세스 권한이 없으면 시간 초과가 발생합니다. 존재하지 않는 것을 액세스하려고하면 "찾을 수 없음"오류가 발생합니다. –

답변

1

람다와 동일한 지역에 같은 VPC에 redis가 있어야합니다. 보안 그룹 설정을 확인하십시오. 그런 다음 EC2 액세스 권한이 있으면 redis cli를 설치하고 redis 연결을 시도하십시오. 연결되면 람다도 연결됩니다. 이전에 말했듯이, 당신은 같은 VPC에 람다를 가져야합니다. 다음은 람다 연결 코드입니다.

console.log('before client initialization') 
    const redisOptions = { 
    host: "xxxx.xxx.xxx.xxx.xxx.amazonaws.com", 
    port: 6379 

    } 

    var client = redis.createClient(redisOptions); 


client.on('connect', function(result) { 
    console.log("connected"); 
    } 
+2

redis 명령을 실행 한 후 client.quit()가 매우 중요합니다. quit()을 호출하지 않으면 람다가 실행을 시간 초과합니다. – user1858991