mirror of
https://github.com/autistic-symposium/backend-and-orchestration-toolkit.git
synced 2025-06-07 22:42:59 -04:00
merge files from the blockchain infra repo (#59)
This commit is contained in:
parent
23f56ef195
commit
2a6449bb85
346 changed files with 29097 additions and 132 deletions
4
code/aws/lambda-function/monitoring_example/.gitignore
vendored
Executable file
4
code/aws/lambda-function/monitoring_example/.gitignore
vendored
Executable file
|
@ -0,0 +1,4 @@
|
|||
!.env.example
|
||||
.env
|
||||
node_modules
|
||||
src/packaged-*.yaml
|
37
code/aws/lambda-function/monitoring_example/Makefile
Executable file
37
code/aws/lambda-function/monitoring_example/Makefile
Executable file
|
@ -0,0 +1,37 @@
|
|||
BASEDIR := "$(PWD)/src"
|
||||
|
||||
CMD := docker run -it --rm \
|
||||
--volume "/var/run/docker.sock:/var/run/docker.sock" \
|
||||
--volume "$(PWD)/src:/var/opt" \
|
||||
--volume ~/.aws:/root/.aws \
|
||||
--env-file .env
|
||||
|
||||
AWS_REGION := $(shell aws configure get region)
|
||||
|
||||
.PHONY: help
|
||||
help:
|
||||
@$(CMD)
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
@$(CMD) build
|
||||
|
||||
.PHONY: validate
|
||||
validate:
|
||||
@$(CMD) validate
|
||||
|
||||
.PHONY: local
|
||||
local:
|
||||
@$(CMD) local invoke "MonitoringTest" \
|
||||
-t "/var/opt/template.yaml" \
|
||||
-e "/var/opt/event.json" \
|
||||
--profile "$(AWS_PROFILE)" \
|
||||
--docker-volume-basedir "$(BASEDIR)"
|
||||
|
||||
.PHONY: logs
|
||||
logs:
|
||||
@$(CMD) logs -n MonitoringTest --stack-name ${STACK_NAME} -t --region ${AWS_REGION} --profile ${AWS_PROFILE}
|
||||
|
||||
.PHONY: package
|
||||
package:
|
||||
@$(CMD) package --template-file ./template.yaml --output-template-file ./packaged-template.yaml --s3-bucket ${S3_BUCKET} --region ${AWS_REGION} --profile ${AWS_PROFILE}
|
9
code/aws/lambda-function/monitoring_example/README.md
Executable file
9
code/aws/lambda-function/monitoring_example/README.md
Executable file
|
@ -0,0 +1,9 @@
|
|||
### Monitoring Lambda Test Function
|
||||
|
||||
Lambda function that looks at its argument and just succeeds or fails based on the input.
|
||||
|
||||
This is used to test our monitoring graphs and alerting rules.
|
||||
|
||||
|
||||
Install [aws-cli](https://aws.amazon.com/cli/) and [sam](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-logs.html).
|
||||
|
4
code/aws/lambda-function/monitoring_example/env_example
Executable file
4
code/aws/lambda-function/monitoring_example/env_example
Executable file
|
@ -0,0 +1,4 @@
|
|||
export AWS_REGION=
|
||||
export S3_BUCKET=
|
||||
export STACK_NAME=
|
||||
export SERVICE_NAME=
|
10
code/aws/lambda-function/monitoring_example/package.json
Executable file
10
code/aws/lambda-function/monitoring_example/package.json
Executable file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "monitoring",
|
||||
"version": "1.0.0",
|
||||
"description": "Lambda function that looks at its argument and just succeeds or fails based on the input.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"locally": "node src/index.js"
|
||||
},
|
||||
"author": "Mia Stein"
|
||||
}
|
13
code/aws/lambda-function/monitoring_example/scripts/deploy-to-aws.sh
Executable file
13
code/aws/lambda-function/monitoring_example/scripts/deploy-to-aws.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit # always exit on error
|
||||
set -o errtrace # trap errors in functions as well
|
||||
set -o pipefail # don't ignore exit codes when piping output
|
||||
|
||||
|
||||
IFS=$'\n\t'
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
|
||||
source "$1"
|
||||
make --makefile=./scripts/deploy.mk all
|
30
code/aws/lambda-function/monitoring_example/scripts/deploy.mk
Executable file
30
code/aws/lambda-function/monitoring_example/scripts/deploy.mk
Executable file
|
@ -0,0 +1,30 @@
|
|||
SAM_INPUT_TEMPLATE=./src/template.yaml
|
||||
SAM_OUTPUT_TEMPLATE=./src/packaged-template.yaml
|
||||
|
||||
.PHONY: validate-env
|
||||
validate-env:
|
||||
@./scripts/validate-env.sh \
|
||||
AWS_ACCESS_KEY_ID \
|
||||
AWS_REGION \
|
||||
AWS_SECRET_ACCESS_KEY \
|
||||
STACK_NAME \
|
||||
S3_BUCKET
|
||||
|
||||
.PHONY: package
|
||||
package: validate-env
|
||||
@aws cloudformation package \
|
||||
--template-file ${SAM_INPUT_TEMPLATE} \
|
||||
--output-template-file ${SAM_OUTPUT_TEMPLATE} \
|
||||
--s3-bucket ${S3_BUCKET} \
|
||||
--region ${AWS_REGION}
|
||||
|
||||
.PHONY: deploy
|
||||
deploy: validate-env package
|
||||
aws cloudformation deploy \
|
||||
--template-file ${SAM_OUTPUT_TEMPLATE} \
|
||||
--stack-name ${SAM_STACK_NAME} \
|
||||
--capabilities CAPABILITY_IAM \
|
||||
--region ${AWS_REGION}
|
||||
|
||||
.PHONY: all
|
||||
all: deploy
|
27
code/aws/lambda-function/monitoring_example/scripts/invoke.sh
Executable file
27
code/aws/lambda-function/monitoring_example/scripts/invoke.sh
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit # always exit on error
|
||||
set -o errtrace # trap errors in functions as well
|
||||
set -o pipefail # don't ignore exit codes when piping output
|
||||
set -o posix # more strict failures in subshells
|
||||
|
||||
IFS=$'\n\t'
|
||||
|
||||
##### RUNNING THE SCRIPT #####
|
||||
# export FUNCTION = <name of the lambda function in aws, can be found by aws lambda list-functions"
|
||||
# source .env
|
||||
# ./scripts/invoke.sh {true|false} [count]
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
./scripts/validate-env.sh AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
|
||||
function=$(aws lambda list-functions | jq -r '.Functions[].FunctionName' | grep -E '^monitoring-lambda' | head -1)
|
||||
payload="{\"forceError\": ${1:-false}}"
|
||||
outpath="/tmp/monitoring-lambda.out"
|
||||
count="${2:-1}"
|
||||
for i in $(seq "${count}"); do
|
||||
aws lambda invoke \
|
||||
--function-name "${function}" \
|
||||
--invocation-type Event \
|
||||
--payload "${payload}" \
|
||||
"${outpath}"
|
||||
done
|
1
code/aws/lambda-function/monitoring_example/scripts/logs.sh
Executable file
1
code/aws/lambda-function/monitoring_example/scripts/logs.sh
Executable file
|
@ -0,0 +1 @@
|
|||
sam logs -n REPLACE-LOGS-NAME --stack-name REPLACE-STACK-NAME -t
|
1
code/aws/lambda-function/monitoring_example/scripts/package.sh
Executable file
1
code/aws/lambda-function/monitoring_example/scripts/package.sh
Executable file
|
@ -0,0 +1 @@
|
|||
sam package --template-file template.yaml --output-template-file packaged.yaml --s3-bucket s3-test-deployment
|
19
code/aws/lambda-function/monitoring_example/scripts/validate-env.sh
Executable file
19
code/aws/lambda-function/monitoring_example/scripts/validate-env.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit # always exit on error
|
||||
set -o errtrace # trap errors in functions as well
|
||||
set -o pipefail # don't ignore exit codes when piping output
|
||||
set -o posix # more strict failures in subshells
|
||||
|
||||
IFS=$'\n\t'
|
||||
|
||||
declare -a missing
|
||||
for var in "$@"; do
|
||||
if [[ -z "${!var}" ]]; then
|
||||
echo "⚠️ ERROR: Missing required environment variable: ${var}" 1>&2
|
||||
missing+=("${var}")
|
||||
fi
|
||||
done
|
||||
if [[ -n "${missing[*]}" ]]; then
|
||||
exit 1
|
||||
fi
|
3
code/aws/lambda-function/monitoring_example/src/event.json
Executable file
3
code/aws/lambda-function/monitoring_example/src/event.json
Executable file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"forceError": true
|
||||
}
|
22
code/aws/lambda-function/monitoring_example/src/index.js
Executable file
22
code/aws/lambda-function/monitoring_example/src/index.js
Executable file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* @name monitoring
|
||||
* @param {Object} context Lambda context object
|
||||
* @return {Object} Object with a message and the original event
|
||||
*/
|
||||
exports.handler = async function(event) {
|
||||
console.log("got event", event);
|
||||
|
||||
if (event.forceError) {
|
||||
throw new Error ("Intentional Error.")
|
||||
}
|
||||
|
||||
return {
|
||||
message: "Work complete.",
|
||||
event
|
||||
};
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const event = require("./event.json");
|
||||
exports.handler(event);
|
||||
}
|
11
code/aws/lambda-function/monitoring_example/src/template.yaml
Executable file
11
code/aws/lambda-function/monitoring_example/src/template.yaml
Executable file
|
@ -0,0 +1,11 @@
|
|||
AWSTemplateFormatVersion: '2010-09-09'
|
||||
Transform: 'AWS::Serverless-2016-10-31'
|
||||
Description: Monitoring test lambda
|
||||
Resources:
|
||||
MonitoringTest:
|
||||
Type: 'AWS::Serverless::Function'
|
||||
Properties:
|
||||
Handler: index.handler
|
||||
Runtime: nodejs8.10
|
||||
Description: Monitoring test lambda
|
||||
MemorySize: 256
|
Loading…
Add table
Add a link
Reference in a new issue