Skip to content

Commit

Permalink
Test Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gernot Glawe committed Feb 12, 2023
1 parent c50b5c9 commit 966eae3
Show file tree
Hide file tree
Showing 45 changed files with 7,994 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@

# Dependency directories (remove the comment below to include it)
# vendor/
lambda_telementry_api/lambda/go/dist
lambda_telementry_api/lambda/py/dist
lambda_telementry_api/lambda/py/package
.DS_Store
lambda_telementry_api/lambda/ts/dist
.vscode
loki_extension/dist
47 changes: 47 additions & 0 deletions img/extension.d2
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Loki logs: {
shape: sequence_diagram
Lambda Service: {
Extensions API : {

}
Telemetry API: {

}
}
Telemetry Extension: {
main : {

}
Extension API Client: {

}
Listener: {

}
Telemetry API Client: {

}
Telemetry Dispatcher: {

}
}

Loki: {

}
Step 1: {
Telemetry Extension.main -> Telemetry Extension.Extension API Client
}

bob: Bobby
awkward small talk: {
alice -> bob: uhm, hi
bob -> alice: oh, hello
icebreaker attempt: {
alice -> bob: what did you have for lunch?
}
unfortunate outcome: {
bob -> alice: that's personal
}
}
}
63 changes: 63 additions & 0 deletions img/extension.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions img/logo-loki.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions lambda_telementry_api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.js
!jest.config.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out
6 changes: 6 additions & 0 deletions lambda_telementry_api/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.ts
!*.d.ts

# CDK asset staging directory
.cdk.staging
cdk.out
1 change: 1 addition & 0 deletions lambda_telementry_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Lambda Test Setup using Loki Telemtry API
61 changes: 61 additions & 0 deletions lambda_telementry_api/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# https://taskfile.dev

version: '3'

vars:
CDK_VER: 2.59.0

includes:
go:
taskfile: ./lambda/go/Taskfile.yml
dir: ./lambda/go
typescript:
taskfile: ./lambda/ts/Taskfile.yml
dir: ./lambda/ts
python:
taskfile: ./lambda/py/Taskfile.yml
dir: ./lambda/py

tasks:

bootstrap:
desc: CDK bootstrap (for beginners)
vars:
ALIAS:
sh: aws iam list-account-aliases --query "AccountAliases[0]" --output=text

cmds:
- npx cdk@{{.CDK_VER}} bootstrap

build:
desc: Build lambdas
cmds:
- task: typescript:build
- task: python:build
- task: go:build

deploy:
desc: 1) Deploy cdk without asking - needs docker
deps: [build]
cmds:
- npx cdk@{{.CDK_VER}} deploy --require-approval never
silent: true

diff:
desc: 2) cdk diff
cmds:
- npx cdk@{{.CDK_VER}} diff --require-approval never
silent: true

destroy:
desc: 3) Destroy cdk without asking - needs docker
cmds:
- npx cdk@{{.CDK_VER}} deploy --require-approval never
silent: true



traffic:
desc: Create traffic on S3 bucket
cmds:
- test/traffic.sh
21 changes: 21 additions & 0 deletions lambda_telementry_api/bin/lambda_telementry_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { LambdaTelementryApiStack } from '../lib/lambda_telementry_api-stack';

const app = new cdk.App();
new LambdaTelementryApiStack(app, 'LambdaTelementryApiStack', {
/* If you don't specify 'env', this stack will be environment-agnostic.
* Account/Region-dependent features and context lookups will not work,
* but a single synthesized template can be deployed anywhere. */

/* Uncomment the next line to specialize this stack for the AWS Account
* and Region that are implied by the current CLI configuration. */
// env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

/* Uncomment the next line if you know exactly what Account and Region you
* want to deploy the stack to. */
// env: { account: '123456789012', region: 'us-east-1' },

/* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
40 changes: 40 additions & 0 deletions lambda_telementry_api/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"app": "npx ts-node --prefer-ts-exts bin/lambda_telementry_api.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true
}
}
8 changes: 8 additions & 0 deletions lambda_telementry_api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
34 changes: 34 additions & 0 deletions lambda_telementry_api/lambda/go/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# https://taskfile.dev

## Build Management only for go

version: '3'




env:
AWS_DEFAULT_REGION: eu-central-1

tasks:
default:
deps: [build]

build:
desc: build go
cmds:
- env GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o dist/main main/main.go
- chmod +x dist/main
- cd dist && zip main.zip main
silent: true

fastdeploy:
desc: Deploy only lambda
deps: [build]
vars:
FN:
sh: aws cloudformation list-exports --query "Exports[?Name == 'telemetry-api-starter-GO-name'].Value" --output text
cmds:
- aws lambda update-function-code --function-name {{.FN}} --zip-file fileb://dist/main.zip


13 changes: 13 additions & 0 deletions lambda_telementry_api/lambda/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module lambda-go

go 1.13

require (
github.com/aws/aws-lambda-go v1.34.1
github.com/aws/aws-sdk-go v1.25.48 // indirect
github.com/aws/aws-sdk-go-v2 v1.17.1
github.com/aws/aws-sdk-go-v2/config v1.17.10
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.17.3
github.com/aws/aws-xray-sdk-go v1.8.0
github.com/aws/smithy-go v1.13.4
)
Loading

0 comments on commit 966eae3

Please sign in to comment.