-
Notifications
You must be signed in to change notification settings - Fork 2
Add new custom resource: elasticsearch.IngestPipeline #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bogdankatishev
wants to merge
6
commits into
master
Choose a base branch
from
feature/elasticsearch-ingestpipeline
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
31a4647
Add new custom resource: elasticsearch.IngestPipeline
bogdankatishev 438fdda
update ReadMe
benbridts 911393f
Add Vpc Support to ElasticSearch
benbridts 0f5e397
Merge pull request #47 from benbridts/vpc-example
bogdankatishev d69a85f
Sign HTTP requests to Amazon Elasticsearch Service
bogdankatishev cf0b80f
Only allow ESHttpPut and ESHttpDelete in lambda_policy
bogdankatishev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Custom resources related to Elasticsearch.""" | ||
| from six import string_types | ||
| from .LambdaBackedCustomResource import LambdaBackedCustomResource | ||
|
|
||
|
|
||
| class IngestPipelineViaVpc(LambdaBackedCustomResource): | ||
| props = { | ||
| 'EsHost': (string_types, True), | ||
| 'PipelineName': (string_types, True), | ||
| 'IngestDocument': (dict, True), | ||
| } | ||
|
|
||
| @classmethod | ||
| def _lambda_policy(cls): | ||
| return { | ||
| "Version": "2012-10-17", | ||
| "Statement": [{ | ||
| "Effect": "Allow", | ||
| "Action": "es:ESHttp*", | ||
| "Resource": "*", | ||
| }], | ||
| } | ||
|
|
||
| @classmethod | ||
| def _update_lambda_settings(cls, settings): | ||
| """ | ||
| Update the default settings for the lambda function. | ||
|
|
||
| :param settings: The default settings that will be used | ||
| :return: updated settings | ||
| """ | ||
| settings['VpcConfig'] = {} # build.py adds the config if the key is present | ||
| return settings | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """ | ||
| Custom resource to create an ingest pipeline in your AWS Elasticsearch Cluster. | ||
| """ | ||
|
|
||
| import json | ||
| import os | ||
|
|
||
| from cfn_custom_resource import CloudFormationCustomResource | ||
| from _metadata import CUSTOM_RESOURCE_NAME | ||
|
|
||
| from elasticsearch import Elasticsearch, RequestsHttpConnection, ElasticsearchException | ||
| from requests_aws4auth import AWS4Auth | ||
|
|
||
| REGION = os.environ['AWS_REGION'] | ||
|
|
||
| class IngestPipelineViaVpc(CloudFormationCustomResource): | ||
| RESOURCE_TYPE_SPEC = CUSTOM_RESOURCE_NAME | ||
|
|
||
| def validate(self): | ||
| self.es_host = self.resource_properties['EsHost'] | ||
| self.pipeline_name = self.resource_properties['PipelineName'] | ||
| self.ingest_doc = self.resource_properties['IngestDocument'] | ||
|
|
||
| def create(self): | ||
| service = 'es' | ||
| credentials = self.get_boto3_session().get_credentials() | ||
| awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, REGION, service, session_token=credentials.token) | ||
|
|
||
| es = Elasticsearch( | ||
| hosts = [{'host': self.es_host, 'port': 443}], | ||
| http_auth = awsauth, | ||
| use_ssl = True, | ||
| verify_certs = True, | ||
| connection_class = RequestsHttpConnection | ||
| ) | ||
|
|
||
| es.ingest.put_pipeline(id=self.pipeline_name, body=json.dumps(self.ingest_doc)) | ||
| return {} | ||
|
|
||
| def update(self): | ||
| return self.create() | ||
|
|
||
| def delete(self): | ||
| service = 'es' | ||
| credentials = self.get_boto3_session().get_credentials() | ||
| awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, REGION, service, session_token=credentials.token) | ||
|
|
||
| es = Elasticsearch( | ||
| hosts = [{'host': self.es_host, 'port': 443}], | ||
| http_auth = awsauth, | ||
| use_ssl = True, | ||
| verify_certs = True, | ||
| connection_class = RequestsHttpConnection | ||
| ) | ||
|
|
||
| try: | ||
| es.ingest.delete_pipeline(id=self.pipeline_name) | ||
| except ElasticsearchException: | ||
| # Assume already deleted | ||
| pass | ||
|
|
||
|
|
||
| handler = IngestPipelineViaVpc.get_handler() |
3 changes: 3 additions & 0 deletions
3
lambda_code/elasticsearch/IngestPipelineViaVpc/requirements.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| git+https://github.com/iRobotCorporation/cfn-custom-resource#egg=cfn-custom-resource | ||
| elasticsearch | ||
| requests-aws4auth |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can scope this down more (definitely for action, possibly for resource)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added commit: cf0b80f which only allows ESHttpPut and ESHttpDelete