https://github.com/mimani68/elk-lambda-query
Eleastich search lambda query
https://github.com/mimani68/elk-lambda-query
aws aws-lambda elasticsearch elk function-as-a-service functions golang serverless
Last synced: about 1 month ago
JSON representation
Eleastich search lambda query
- Host: GitHub
- URL: https://github.com/mimani68/elk-lambda-query
- Owner: mimani68
- Created: 2023-05-11T16:12:08.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-11T16:23:04.000Z (about 3 years ago)
- Last Synced: 2025-04-03T06:36:49.488Z (about 1 year ago)
- Topics: aws, aws-lambda, elasticsearch, elk, function-as-a-service, functions, golang, serverless
- Language: Go
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Elasticsearch indirect query
This is a sample template for ***elk-function-as-service*** - Below is a brief explanation of what we have generated for you:
```bash
.
├── Makefile <-- Make to automate build
├── README.md <-- This instructions file
├── update-report <-- Source code for a lambda function
│ ├── main.go <-- Lambda function code
│ └── main_test.go <-- Unit tests
├── query <-- Source code for a lambda function
│ ├── main.go <-- Lambda function code
│ └── main_test.go <-- Unit tests
└── template.yaml
```
## Requirements
* AWS CLI already configured with Administrator permission
* [Docker installed](https://www.docker.com/community-edition)
* [Golang](https://golang.org)
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
## Setup process
### Installing dependencies & building the target
In this example we use the built-in `sam build` to automatically download all the dependencies and package our build target.
Read more about [SAM Build here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html)
The `sam build` command is wrapped inside of the `Makefile`. To execute this simply run
```shell
make
```
### Local development
**Invoking function locally through local API Gateway**
```bash
sam local start-api
```
If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function `http://localhost:3000/query` or `http://localhost:3000/update`
**SAM CLI** is used to emulate both Lambda and API Gateway locally and uses our `template.yaml` to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The following excerpt is what the CLI will read in order to initialize an API and its routes:
```yaml
...
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /query
Method: get
```
## Packaging and deployment
AWS Lambda Golang runtime requires a flat folder with the executable generated on build step. SAM will use `CodeUri` property to know where to look up for the application:
```yaml
...
QueryFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: query/
...
```
To deploy your application for the first time, run the following in your shell:
```bash
sam deploy --guided
```
The command will package and deploy your application to AWS, with a series of prompts:
* **Stack Name**: The name of the stack to deploy to CloudFormation. This should be unique to your account and region, and a good starting point would be something matching your project name.
* **AWS Region**: The AWS region you want to deploy your app to.
* **Confirm changes before deploy**: If set to yes, any change sets will be shown to you before execution for manual review. If set to no, the AWS SAM CLI will automatically deploy application changes.
* **Allow SAM CLI IAM role creation**: Many AWS SAM templates, including this example, create AWS IAM roles required for the AWS Lambda function(s) included to access AWS services. By default, these are scoped down to minimum required permissions. To deploy an AWS CloudFormation stack which creates or modifies IAM roles, the `CAPABILITY_IAM` value for `capabilities` must be provided. If permission isn't provided through this prompt, to deploy this example you must explicitly pass `--capabilities CAPABILITY_IAM` to the `sam deploy` command.
* **Save arguments to samconfig.toml**: If set to yes, your choices will be saved to a configuration file inside the project, so that in the future you can just re-run `sam deploy` without parameters to deploy changes to your application.
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
### Testing
We use `testing` package that is built-in in Golang and you can simply run the following command to run our tests:
```shell
go test -v ./elks/
```
## Snapshot
