AWSGlue是否可以使用IAM身份验证连接到Elasticsearch?
创始人
2024-09-25 16:30:28
0

是的,AWS Glue可以使用IAM身份验证连接到Elasticsearch,这需要使用Elasticsearch Service角色和AWS Glue Dev Endpoint。以下是所需的步骤及代码示例:

  1. 创建Elasticsearch Service角色并配置策略,以便AWS Glue可以访问Elasticsearch。例如:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "es:*" ], "Resource": [ "arn:aws:es:region:account-id:domain/test-domain" ] } ] }

  1. 在AWS Glue中创建Dev Endpoint并分配所需的角色。例如:

import boto3

glue = boto3.client('glue')

response = glue.create_dev_endpoint( EndpointName='test-endpoint', RoleArn='arn:aws:iam::account-id:role/service-role/aws-glue-service-role', SecurityGroupIds=['sg-12345678'], SubnetId='subnet-12345678', PublicKey='ssh-rsa AAA... user@host' )

  1. 在Glue Dev Endpoint中使用Elasticsearch Python库连接到Elasticsearch。例如:

import boto3 from elasticsearch import Elasticsearch, RequestsHttpConnection from requests_aws4auth import AWS4Auth

region = 'region' session = boto3.Session(region_name=region) credentials = session.get_credentials() awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, 'es', session_token=credentials.token)

host = 'search-test-domain-abc123xyz.region.es.amazonaws.com' es = Elasticsearch( hosts=[{'host': host, 'port': 443}], http_auth=awsauth, use_ssl=True, verify_certs=True, connection_class=RequestsHttpConnection )

连接到elasticsearch成功,可以执行搜索或索引操作

es.search(index="test-index", body={"query": {"match_all": {}}}) es.index(index="test-index", id=1, body={"text": "example"})

相关内容

热门资讯

五分钟辅助!hhpoker是真... 五分钟辅助!hhpoker是真的还是假的,哈糖大菠萝有挂吗,积累教程(有挂详情)1、每一步都需要思考...
八分钟辅助!epoker免费透... 八分钟辅助!epoker免费透视脚本,hhpoker辅助器,手段教程(有挂透明挂)1、每一步都需要思...
第二分钟辅助!we-poker... 第二分钟辅助!we-poker正规吗,hhpoker一直输有挂吗,总结教程(的确有挂)1、hhpok...
八分钟辅助!pokermast... 八分钟辅助!pokermaster辅助器,wpk透视插件,策略教程(有挂方法)1、pokermast...
2分钟辅助!拱趴大菠萝有什么挂... 2分钟辅助!拱趴大菠萝有什么挂,hhpoker必备开挂,烘培教程(有挂秘籍)1、拱趴大菠萝有什么挂公...
4分钟辅助!wepoker软件... 4分钟辅助!wepoker软件靠谱么,wepoker免费脚本,法门教程(有挂详细)1、用户打开应用后...
第九分钟辅助!wepoker有... 第九分钟辅助!wepoker有脚本吗,wepoker透视脚本免费app,手筋教程(有挂方式)1、we...
第九分钟辅助!德普之星私人局辅... 第九分钟辅助!德普之星私人局辅助器,德普之星辅助工具如何打开,步骤教程(有挂猫腻)1、德普之星辅助工...
五分钟辅助!wepoker可以... 五分钟辅助!wepoker可以开透视吗,pokemmo手机版透视脚本,讲义教程(有挂神器)在进入po...
五分钟辅助!pokermast... 五分钟辅助!pokermaster修改器,wepoker安装教程,教程书教程(证实有挂)1、下载好p...