holy-lambda

Chris Lowe 2021-05-14T07:05:25.194Z

@chris.lowe.uk has joined the channel

Chris Lowe 2021-05-14T07:41:08.203Z

Morning @karol.wojcik While the getting started documentation is being worked on, and following on from this https://github.com/FieryCod/holy-lambda/issues/42, the intention here is for me to be a guinea pig and go through the process of deployment with holy-lambda to discover what sort things to cover in the docs. Where I am: I’m coming into this cold from both a holy-lambda and babashka perspective. I am familiar with using Lambda’s (mostly node.js to date) and have had very fleeting experiences with SAM. My goal: Create a Clojure Java Native Lambda that, in response to S3 events, transforms file content between two S3 buckets (input and output). I’ll add what I can to this thread which will, hopefully, be of use to others.

👍 2
Karol Wójcik 2021-05-17T06:50:59.232800Z

Answering your questions; 1. Lein new or clj-new will always generate the core.cljc with a single lambda ExampleLambdaFunction. It’s declared in template.yml since it’s just AWS SAM file. On bb.edn you declare the default function which should be invoked or which lambda logs should be taken from cloud watch when bb stack:invoke or bb stack:logs are invoked. Default function might be overridden by passing your function name to those commands ;) runtime should be changed by specifying different name of the runtime in bb.edn. bb stack:sync is required after doing so. 2. bb stack:sync syncs required dependencies for the stack. It downloads deps, deploys necessary layers and sync babashka pods. It’s very useful since you don’t want to pack all the dependencies from /$HOME/.m2 but rather the dependencies you use in your project. ;) I would rather not change the name of the command. bb stack:sync sometimes deploys the layer (and will in future auto update the version of the layer) 3. default profile is used, but maybe it should be changed?

Chris Lowe 2021-05-14T07:44:56.203300Z

lein new holy-lambda holy-lambda-gs

cd holy-lambda-gs

git init
git add .
git commit -m 'initial checkin'

Chris Lowe 2021-05-14T07:48:31.203500Z

This will be done on a Mac (Big Sur with brew)

Chris Lowe 2021-05-14T07:51:15.203700Z

Install https://github.com/babashka/babashka (the project doesn’t appear to be linked anywhere from HL docs)

bash < <(curl -s )
This installs babashka globally.

Chris Lowe 2021-05-14T07:53:00.204100Z

From the git folder, verify the babashka install worked:

holy-lambda-gs (main) $ ls | bb -i '(filter #(-> % io/file .isDirectory) *input*)'
("resources" "src")

Chris Lowe 2021-05-14T07:55:59.204300Z

Template change request: Using bb generates a folder .cpcache, can this be added to .gitignore?

holy-lambda-gs (main) $ git status .
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.cpcache/

👍 1
Karol Wójcik 2021-05-14T08:01:48.204700Z

Thanks. I've added it to .gitignore. Will be available in next release 🙂

🙌 1
Chris Lowe 2021-05-14T08:19:45.205100Z

Ok, where to begin. Initial advice (issue comment) was to run bb stack:sync and use bb stack:doctor But I am coming at this completely cold. There are questions at this point :-) Question 1: In generating the project using lein, what do I have? It would be good to have an overview of what would be produced, e.g. this will create a Lambda function named XXX, running on runtime YY Y (or whatever) • how you rename the Lambda function (there are references to ExampleLambdaFunction in template.yml and bb.edn)? • how do you choose and configure a runtime (JVM, GraalVM, babashka)? Question 2: What does stack:sync do exactly? From README.md, > stack:sync > Syncs project & dependencies from either: > - <Clojure> project.clj > - <Clojure> deps.edn > - <Babashka> bb.edn:runtime:pods In a AWS world, the use of terminology could be confusing, we will produce code and deploy (sync) code to the cloud. Would something like “init-deps” be a better choice here? Question 3: I’m used to having to perform some sort of AWS init to set my creds. Where should that happen? Or is HL just using the default profile?

Chris Lowe 2021-05-14T08:21:28.205300Z

Running bb stack:sync failed for me:

holy-lambda-gs (main) $ bb stack:sync
[holy-lambda] Command <stack:sync>
[holy-lambda] Project not synced yet. Syncing with docker image!
[holy-lambda] Project did not sync properly. Remove .holy-lambda directory and run stack:sync
----- Error --------------------------------------------------------------------
Type:     java.io.FileNotFoundException
Message:  .holy-lambda/clojure/deps.edn (No such file or directory)

Chris Lowe 2021-05-14T08:23:16.205500Z

I followed the recommendation to remove .holy-lambda and try again, but had the same result:

holy-lambda-gs (main) $ rm -rf .holy-lambda/
holy-lambda-gs (main) $ bb stack:sync
[holy-lambda] Command <stack:sync>
[holy-lambda] Project not synced yet. Syncing with docker image!
[holy-lambda] Unable to sync docker image content with .holy-lambda project directory!
[holy-lambda] Project did not sync properly. Remove .holy-lambda directory and run stack:sync
----- Error --------------------------------------------------------------------
Type:     java.io.FileNotFoundException
Message:  .holy-lambda/clojure/deps.edn (No such file or directory)

Chris Lowe 2021-05-14T08:23:48.205700Z

(currently running stack:doctor)

Chris Lowe 2021-05-14T08:24:32.205900Z

Command reports something is missing

...
[holy-lambda] Commands ("clj-kondo") not found. Install all then run: bb doctor

Karol Wójcik 2021-05-14T08:25:35.206100Z

Try bb stack:prune then bb stack:sync

👀 1
Karol Wójcik 2021-05-14T08:25:48.206400Z

I will check new template

Chris Lowe 2021-05-14T08:26:37.206600Z

Looks like the prune task is not available in the template I used:

bb stack:prune 
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  File does not exist: stack:prune

Karol Wójcik 2021-05-14T08:27:18.206900Z

Sorry. It should be bb stack:purge

Chris Lowe 2021-05-14T08:28:23.207100Z

np. same result:

holy-lambda-gs (main) $  bb stack:purge
[holy-lambda] Command <stack:purge>
[holy-lambda] Purging build artifacts:

 - .aws
 - .holy-lambda
 - .cpcache
 - 
 - node_modules

[holy-lambda] Build artifacts purged
holy-lambda-gs (main) $ bb stack:sync
Downloading: org/clojure/clojure/1.10.3/clojure-1.10.3.pom from central
Downloading: org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.pom from central
Downloading: org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom from central
Downloading: io/github/FieryCod/holy-lambda/0.1.45/holy-lambda-0.1.45.pom from clojars
Downloading: com/amazonaws/aws-lambda-java-core/1.2.1/aws-lambda-java-core-1.2.1.pom from central
Downloading: io/github/FieryCod/holy-lambda-default-retriever/0.0.5/holy-lambda-default-retriever-0.0.5.pom from clojars
Downloading: metosin/jsonista/0.3.2/jsonista-0.3.2.pom from clojars
Downloading: com/fasterxml/jackson/core/jackson-core/2.12.2/jackson-core-2.12.2.pom from central
Downloading: com/fasterxml/jackson/core/jackson-databind/2.12.2/jackson-databind-2.12.2.pom from central
Downloading: com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.2/jackson-datatype-jsr310-2.12.2.pom from central
Downloading: com/fasterxml/jackson/jackson-base/2.12.2/jackson-base-2.12.2.pom from central
Downloading: com/fasterxml/jackson/module/jackson-modules-java8/2.12.2/jackson-modules-java8-2.12.2.pom from central
Downloading: com/fasterxml/jackson/jackson-bom/2.12.2/jackson-bom-2.12.2.pom from central
Downloading: com/fasterxml/jackson/jackson-parent/2.12/jackson-parent-2.12.pom from central
Downloading: com/fasterxml/oss-parent/41/oss-parent-41.pom from central
Downloading: com/fasterxml/jackson/core/jackson-annotations/2.12.2/jackson-annotations-2.12.2.pom from central
Downloading: com/fasterxml/jackson/core/jackson-core/2.12.2/jackson-core-2.12.2.jar from central
Downloading: org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar from central
Downloading: com/fasterxml/jackson/core/jackson-databind/2.12.2/jackson-databind-2.12.2.jar from central
Downloading: com/fasterxml/jackson/core/jackson-annotations/2.12.2/jackson-annotations-2.12.2.jar from central
Downloading: org/clojure/clojure/1.10.3/clojure-1.10.3.jar from central
Downloading: org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar from central
Downloading: io/github/FieryCod/holy-lambda/0.1.45/holy-lambda-0.1.45.jar from clojars
Downloading: com/amazonaws/aws-lambda-java-core/1.2.1/aws-lambda-java-core-1.2.1.jar from central
Downloading: com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.12.2/jackson-datatype-jsr310-2.12.2.jar from central
Downloading: io/github/FieryCod/holy-lambda-default-retriever/0.0.5/holy-lambda-default-retriever-0.0.5.jar from clojars
Downloading: metosin/jsonista/0.3.2/jsonista-0.3.2.jar from clojars
[holy-lambda] Command <stack:sync>
[holy-lambda] Project not synced yet. Syncing with docker image!
[holy-lambda] Project did not sync properly. Remove .holy-lambda directory and run stack:sync
----- Error --------------------------------------------------------------------
Type:     java.io.FileNotFoundException
Message:  .holy-lambda/clojure/deps.edn (No such file or directory)

Karol Wójcik 2021-05-14T08:28:26.207300Z

@chris.lowe.uk What is you template version? It should be: 0.1.52

Chris Lowe 2021-05-14T08:29:39.207500Z

ls ~/.m2/repository/holy-lambda/lein-template/
0.1.52				maven-metadata-clojars.xml	maven-metadata-clojars.xml.sha1	resolver-status.properties

Chris Lowe 2021-05-14T08:29:52.207700Z

looks like I’m using the expected version

Karol Wójcik 2021-05-14T08:31:52.207900Z

Could you please send whole report from bb stack:doctor?

Chris Lowe 2021-05-14T08:33:30.208100Z

bb stack:doctor
[holy-lambda] Command <stack:doctor>

[holy-lambda] ---------------------------------------
[holy-lambda]  Checking health of holy-lambda stack
[holy-lambda]  Home directory is:        /Users/lowecg
[holy-lambda]  AWS directory is:         /Users/lowecg/.aws
[holy-lambda]  Babashka tasks version:   0.0.1
[holy-lambda]  Babashka version:         babashka v0.4.1
[holy-lambda]  Runtime:                  :native
[holy-lambda]  Runtime entrypoint:       holy-lambda-gs.core
[holy-lambda]  Stack name:               holy-lambda-template-stack
[holy-lambda]  S3 Bucket name:           holy-lambda-template-bucket
[holy-lambda]  S3 Bucket prefix:         holy-lambda
[holy-lambda] ---------------------------------------

[holy-lambda] :runtime looks good
[holy-lambda] :runtime:entrypoint looks good
[holy-lambda] :stack:capabilities looks good
[holy-lambda] :runtime:bootstrap-file does not exists. Default bootstrap file for :native runtime will be used!
[holy-lambda] :runtime:version is supported only for :babashka runtime
[holy-lambda] :runtime:pods are supported only for :babashka runtime
[holy-lambda] :stack:name looks good
[holy-lambda] property :mvn/local-repo in file deps.edn is correct
[holy-lambda] property :mvn/local-repo in file bb.edn is correct
[holy-lambda] Stack is not synced! Run: stack:sync
[holy-lambda] :infra:region definition looks good
[holy-lambda] :infra:bucket-prefix looks good
[holy-lambda] :stack:template looks good
[holy-lambda] :infra:bucket-name looks good, but holy-lambda-template-bucket does not exists (use bb :bucket:create)
[holy-lambda] Required commands ["aws" "sam" "bb" "docker" "clojure" "zip" "id" "clj-kondo" "bash"] installed!

[holy-lambda] Validating template.yml

	SAM CLI now collects telemetry to better understand customer needs.

	You can OPT OUT and disable telemetry collection by setting the
	environment variable SAM_CLI_TELEMETRY=0 in your shell.
	Thanks for your help!

	Learn More: 

2021-05-14 09:33:09 Loading policies from IAM...
2021-05-14 09:33:12 Finished loading policies from IAM.
/Users/lowecg/source/private-github/holy-lambda-gs/template.yml is a valid SAM Template

Chris Lowe 2021-05-14T08:34:20.208300Z

I’ve since installed https://github.com/clj-kondo/clj-kondo/blob/master/doc/install.md

brew install borkdude/brew/clj-kondo

Karol Wójcik 2021-05-14T08:37:58.208800Z

Your stack looks good. I'm wondering what might go wrong in that setup. I will need some more of your help. May we have a quick call?

Chris Lowe 2021-05-14T08:38:39.209100Z

sure thing - give me 15 mins.

Karol Wójcik 2021-05-14T08:45:54.209300Z

Just let me know when you're ready 🙂

Chris Lowe 2021-05-14T08:51:33.209500Z

ready

Karol Wójcik 2021-05-14T08:52:43.209700Z

Send you a invitation link in private 🙂

Chris Lowe 2021-05-14T09:42:35.209900Z

For the benefit of this thread - the cause of the stack:sync issue was docker not running. Some additional docker checks will be built into the bb tasks to better protect people, like me, from themselves!

👍 1
borkdude 2021-05-14T10:42:05.210300Z

@borkdude has joined the channel

❤️ 1
👋 3
Karol Wójcik 2021-05-14T10:53:40.210800Z

Uuu 😄 What a pleasure to have you here @borkdude 🙂

👋 1
Karol Wójcik 2021-05-14T15:15:36.212500Z

Thank you @chris.lowe.uk @martinklepsch for today bug hunting! I will get on those bugs today's evening or early in the morning. I will notify you, when I finish so that you can retest 🙂

Karol Wójcik 2021-05-16T11:05:54.214Z

@martinklepsch https://github.com/FieryCod/holy-lambda/issues/43 It has been fixed in https://github.com/FieryCod/holy-lambda/commit/f40e9e0a5ec5870211ceded1084b478c03d1e6ae Please use https://github.com/FieryCod/holy-lambda/commit/f40e9e0a5ec5870211ceded1084b478c03d1e6ae for babashka tasks and let me know whether it works on your end. • @chris.lowe.uk @martinklepsch Bucket creation will now fail early: https://github.com/FieryCod/holy-lambda/commit/b11cb73600f6dbbeb6b1e364c5346d9fdde8fc0a Please try to use common bucket name like "example", and report if it works on your end 🙂@chris.lowe.uk bb stack:sync will not run if docker is not running 🙂 https://github.com/FieryCod/holy-lambda/commit/474729795b70864246fba6062c3ea02fdbad2324

🙌 1
Chris Lowe 2021-05-17T08:17:21.233200Z

Good example of poka-yoke 😄