Skip to content

Commit

Permalink
Use AWS_REGION.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Dec 26, 2022
1 parent f1d1ca2 commit 245de23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Create an OpenSearch domain in (AWS) which support IAM based AuthN/AuthZ.
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export AWS_SESSION_TOKEN=
export AWS_REGION=
export OPENSEARCH_ENDPOINT=https://....us-west-2.es.amazonaws.com
export OPENSEARCH_REGION=us-west-2
bundle exec ruby example.rb
```
Expand Down
12 changes: 6 additions & 6 deletions example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@

signer = Aws::Sigv4::Signer.new(
service: 'es',
region: ENV['OPENSEARCH_REGION'] || 'us-east-1',
region: ENV['AWS_REGION'] || 'us-east-1',
access_key_id: ENV['AWS_ACCESS_KEY_ID'] || raise('Missing AWS_ACCESS_KEY_ID.'),
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'] || raise('Missing AWS_SECRET_ACCESS_KEY.'),
session_token: ENV['AWS_SESSION_TOKEN']
)

client = OpenSearch::Aws::Sigv4Client.new({
host: ENV['OPENSEARCH_ENDPOINT'] || raise('Missing OPENSEARCH_ENDPOINT.')
# log: true
host: ENV['OPENSEARCH_ENDPOINT'] || raise('Missing OPENSEARCH_ENDPOINT.'),
log: false
}, signer)

info = client.info
puts info['version']['distribution'] + ': ' + info['version']['number']

# create an index
index = 'sample-index'
index = 'movies'
client.indices.create(index: index)

begin
# index data
document = { first_name: 'Bruce' }
document = { title: 'Moneyball', director: 'Bennett Miller', year: 2011 }
client.index(index: index, body: document, id: '1', refresh: true)

# wait for the document to index
sleep(3)

# search for the document
results = client.search(body: { query: { match: { first_name: 'bruce' } } })
results = client.search(body: { query: { match: { director: 'miller' } } })
results['hits']['hits'].each do |hit|
puts hit
end
Expand Down

0 comments on commit 245de23

Please sign in to comment.