【发布时间】:2020-05-28 02:24:18
【问题描述】:
我正在使用无服务器框架来实现无服务器项目。我在 serverless.yml 文件中添加了一些配置来为 aws elasticsearch 服务创建实例,该服务已成功创建。然后我在我的处理程序中创建了一个弹性搜索客户端并对其进行 ping 测试。 因此,当我在本地系统上从无服务器离线 ping 弹性搜索客户端时,它工作正常并得到“真实”响应,但是当我在 aws lambda 上部署相同的代码时,它在 30 秒前没有响应后超时。
已经给出了所有可能需要的政策,但没有成功。
Serverless.yml:-
ElasticSearchInstance:
Type: AWS::Elasticsearch::Domain
Properties:
EBSOptions:
EBSEnabled: true
VolumeType: gp2
VolumeSize: 10
ElasticsearchClusterConfig:
InstanceType: t2.small.elasticsearch
InstanceCount: 1
DedicatedMasterEnabled: false
ZoneAwarenessEnabled: false
ElasticsearchVersion: 7.1
Handler.js:-
var {Client} = require('elasticsearch');
var client = new Client({
host: 'Aws elasticsearch endpoint',
log: 'trace'
});
module.exports.elasticSearchPing = async () => {
try {
console.log('Inside elasticSearchPing function!!!!');
const res = await client.ping({requestTimeout: 900000});
console.log('Res: ', res);
return {
statusCode: 200,
body: JSON.stringify({ message: 'Connection successful with elasticSearch.' })
}
} catch (err) {
console.log('err: ', err);
return {
statusCode: err.statusCode || 500,
headers: { 'Content-Type': 'text/plain' },
body: 'Error connecting elasticsearch.'
}
}
}
【问题讨论】:
标签: node.js aws-lambda amazon-cognito serverless-framework aws-elasticsearch