Skip to content

Commit

Permalink
update sample, add simple CI config
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer committed Nov 9, 2023
1 parent f54ce5b commit b39fecd
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 29 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI Tests

on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install and start LocalStack
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
run: |
docker pull localstack/localstack-pro &
pip install localstack terraform-local
localstack start -d
- name: Run tests
env:
LUMIGO_TRACER_TOKEN: ${{ secrets.LUMIGO_TRACER_TOKEN }}
run: |
make deploy
make invoke
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.terraform*
terraform.tfstate*
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FUNC_NAME ?= func1

usage: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/:.*##\s*/##/g' | awk -F'##' '{ printf "%-20s %s\n", $$1, $$2 }'

deploy: ## Deploy the sample app
if [ "$$LUMIGO_TRACER_TOKEN" = "" ]; then \
echo "Please configure the LUMIGO_TRACER_TOKEN environment variable"; \
exit 1; \
fi

cp lambdas/handler.* /tmp/
(cd /tmp; zip testlambda.zip handler.py handler.js)

tflocal init
rm -f terraform.tfstate
TF_VAR_LUMIGO_TRACER_TOKEN=$$LUMIGO_TRACER_TOKEN tflocal apply -auto-approve

invoke: ## Invoke test Lambda function
awslocal lambda invoke --function-name $(FUNC_NAME) /tmp/tmp.out

hot-reload: ## Start Lambda hot reloading session
awslocal lambda update-function-code --function-name $(FUNC_NAME) --s3-bucket hot-reload --s3-key "$$(pwd)/lambdas"

.PHONY: deploy hot-reload
17 changes: 17 additions & 0 deletions lambdas/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { DynamoDB } = require('@aws-sdk/client-dynamodb');
const { SQS } = require('@aws-sdk/client-sqs');

exports.handler = async (event) => {
console.log(JSON.stringify(event));

const ddb = new DynamoDB();
const result = await ddb.scan({TableName: "test"});
console.log("DynamoDB result", result);

const sqs = new SQS();
const params = {QueueUrl: "http://localhost:4566/000000000000/test", MessageBody: "test 123"};
const result2 = await sqs.sendMessage(params);
console.log("SQS result", result2);

return "Hello from LocalStack!";
}
2 changes: 2 additions & 0 deletions lambdas/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def handler(*args, **kwargs):
print("Debug output from Lambda function")
37 changes: 37 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
variable "LUMIGO_TRACER_TOKEN" {
type = string
}

resource "aws_dynamodb_table" "test" {
hash_key = "id"
billing_mode = "PAY_PER_REQUEST"
name = "test"

attribute {
name = "id"
type = "S"
}
}

resource "aws_sqs_queue" "test" {
name = "test"
}

resource "aws_lambda_function" "func1" {
function_name = "func1"
role = "arn:aws:iam::000000000000:role/r1"
handler = "handler.handler"
runtime = "nodejs18.x"
layers = ["arn:aws:lambda:us-east-1:114300393969:layer:lumigo-node-tracer:252"]
# Python layer: arn:aws:lambda:us-east-1:114300393969:layer:lumigo-python-tracer:252
filename = "/tmp/testlambda.zip"
timeout = 30
environment {
variables = {
"AWS_LAMBDA_EXEC_WRAPPER": "/opt/lumigo_wrapper",
"LUMIGO_DEBUG": "true",
"LUMIGO_PROPAGATE_W3": "true",
"LUMIGO_TRACER_TOKEN": var.LUMIGO_TRACER_TOKEN
}
}
}
29 changes: 0 additions & 29 deletions run.sh

This file was deleted.

0 comments on commit b39fecd

Please sign in to comment.