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"})

相关内容

热门资讯

一分钟揭秘!微扑克有辅助软件吗... 一分钟揭秘!微扑克有辅助软件吗,aapoker挂,我来教教你(固有有挂)1、aapoker挂ai辅助...
重大发现!wpk德州辅助,we... 重大发现!wpk德州辅助,wepoke有挂,微扑克教程(原本有挂)1.wepoke有挂 ai辅助创建...
总算明白!微扑克辅助器是真的么... 总算明白!微扑克辅助器是真的么,德州ai辅助有用,力荐教程(都是是真的有挂)1、构建自己的微扑克辅助...
玩家必备科技!gg扑克辅助,w... 玩家必备科技!gg扑克辅助,wepoke辅助有挂,AI教程(确实真的是有挂)1、在wepoke辅助有...
重大来袭!cloudpoker... 重大来袭!cloudpoker辅助器,wepoke真的有挂,力荐教程(固有真的有挂)1、wepoke...
最新技巧!wepoke透明真的... 最新技巧!wepoke透明真的吗,智星德州菠萝有挂吗,AI教程(最初有挂);人气非常高,ai更新快且...
一分钟快速了解!德州微扑克辅助... 一分钟快速了解!德州微扑克辅助,德州微扑克辅助,高科技教程(好像存在有挂)是一款可以让一直输的玩家,...
一分钟教会你!wpk有吗,德州... 一分钟教会你!wpk有吗,德州ai辅助软件,玩家教你(固有是真的有挂)德州ai辅助软件辅助器中分为三...
实操分享!微扑克辅助,德州ai... 实操分享!微扑克辅助,德州ai机器人,科技教程(真是有挂)1、超多福利:超高返利,海量正版游戏,德州...
玩家必看科普!微扑克有辅助软件... 自定义aapoker辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不...