From 67fca10ab822ce398cefb9f7875cdd12fecf6d9e Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Wed, 22 Nov 2023 15:11:32 +0000 Subject: [PATCH] add initial script --- aws-lambda-project/.gitignore | 38 ++++++++++++++++++++++ aws-lambda-project/.localstack/init-aws.sh | 33 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 aws-lambda-project/.gitignore mode change 100644 => 100755 aws-lambda-project/.localstack/init-aws.sh diff --git a/aws-lambda-project/.gitignore b/aws-lambda-project/.gitignore new file mode 100644 index 00000000..ef56dce9 --- /dev/null +++ b/aws-lambda-project/.gitignore @@ -0,0 +1,38 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Misc ### +*.log +.DS_Store +docker/volume/ \ No newline at end of file diff --git a/aws-lambda-project/.localstack/init-aws.sh b/aws-lambda-project/.localstack/init-aws.sh old mode 100644 new mode 100755 index f1f641af..a35e15fd --- a/aws-lambda-project/.localstack/init-aws.sh +++ b/aws-lambda-project/.localstack/init-aws.sh @@ -1 +1,34 @@ #!/usr/bin/env bash + +# Set the JAR file path +JAR_FILE="target/aws-lambda-project-0.0.1-SNAPSHOT-aws.jar" + +# Check if the JAR file exists +if [ -f "$JAR_FILE" ]; then + # Zip the JAR file + zip -j function.zip "$JAR_FILE" + + # Create Lambda function + awslocal lambda create-function \ + --function-name localstack-lambda-url-example \ + --runtime java17 \ + --zip-file fileb://function.zip \ + --handler org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest \ + --role arn:aws:iam::000000000000:role/lambda-role + + echo "created lambda function" + + awslocal lambda create-function-url-config \ + --function-name localstack-lambda-url-example \ + --auth-type NONE + + echo "created function URL" + + awslocal lambda invoke --function-name localstack-lambda-url-example \ + --cli-binary-format raw-in-base64-out \ + --payload '{"body": "{\"name\": \"profile\"}" }' output.txt + + echo "invoked lambda function" +else + echo "Error: JAR file not found at $JAR_FILE" +fi