【问题标题】:No error in executing python function but still index not creating in elasticsreach执行python函数没有错误,但仍然没有在elasticsreach中创建索引
【发布时间】:2021-11-03 14:39:00
【问题描述】:

我创建了一个 python lambda 函数来获取 route53 中发生的任何更改集并将其推送到 Elasticsearch。

下面是我的 Python 函数

import json
import uuid
import sys
import re
from datetime import datetime
from elasticsearch import Elasticsearch, RequestsHttpConnection
from elasticsearch import TransportError

def lambda_handler(event, context):
    mydump = json.dumps(event)
    myload = json.loads(mydump)
    indexName = "routeindexname"
    logstashIndex = indexName + '-' + datetime.now().strftime("%Y.%m.%d")
    es = Elasticsearch(["192.168.21.150"], port=8200, connection_class = RequestsHttpConnection)
    es.indices.create(index=logstashIndex, ignore=400)
    id1 = uuid.uuid4()
    es.index(index=logstashIndex, id=str(id1), body=myload)
    print("Successly Created - Index: {}".format(logstashIndex))
         
    return {
        'statusCode': 200,
        'body': json.dumps('Successfully exported logs to ELK')
    }

下面是我的控制台输出

START RequestId: c45ab4ff-58c4-47d9-a747-e2af40b02z23 Version: $LATEST
END RequestId: c45ab4ff-58c4-47d9-a747-e2af40b02z23
REPORT RequestId: c45ab4ff-58c4-47d9-a747-e2af40b02z23  Duration: 3003.62 ms    Billed Duration: 3000 ms    Memory Size: 128 MB Max Memory Used: 28 MB  
2021-09-06T13:35:30.809Z c45ab4ff-58c4-47d9-a747-e2af40b02z23 Task timed out after 3.00 seconds

当我将print(id1) 放在id1 下方时,它会显示在控制台中,但之后似乎没有任何效果。 似乎es.index 不起作用。 验证时检查 elasticsearch 索引也没有创建。

弹性搜索 = 7.14

Python = 3.8

不知道我错过了哪里。

【问题讨论】:

    标签: python-3.x elasticsearch aws-lambda


    【解决方案1】:

    我想通了。 lambda 函数没有任何问题。

    我必须向 Lambda 函数添​​加与 ELK 堆栈相同的适当 VPC、子网和安全性,并且它起作用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-26
      • 2012-04-23
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      相关资源
      最近更新 更多