Hi!
Has anyone used Crystal with AWS Lambda? any examples out there that I can take a look at ?
Thank you!
Hi!
Has anyone used Crystal with AWS Lambda? any examples out there that I can take a look at ?
Thank you!
Some resources you might find useful (I just got them from searching the web):
Thank you! I’ll take a look and update this with my experiences
It took me forever to get back to this, but here’s a short working example of Crystal code in a lambda - maybe it will help someone else:
cd /tmp
crystal init app crystal-lambda01
cd crystal-lambda01
mkdir bin
cat << EOF >> ./shard.yml
dependencies:
crambda:
path: ./crambda
EOF
git clone https://github.com/lambci/crambda.git
cd crambda/
git fetch origin pull/2/head:jgaskins/patch-1
git merge jgaskins/patch-1
cd ..
shards install
cat << EOF > ./src/crystal-lambda01.cr
require "json"
require "crambda"
Crambda.run_handler do |event, context|
{ "hello from Crystal: #{Crystal::VERSION} - also wombats" }
end
EOF
shards install && crystal build --no-debug src/crystal-lambda01.cr -o /dev/null
bootstrap
docker run --rm \
-v /tmp/crystal-lambda01:/app \
-w /app crystallang/crystal:1.10.1-alpine \
sh -c 'shards install && crystal build --no-debug --static src/crystal-lambda01.cr -o bin/bootstrap && strip bin/bootstrap'
cd bin
zip lambda.zip bootstrap
aws lambda create-function \
--region=us-west-1 \
--function-name=crystal_test01 \
--runtime=provided.al2 \
--package-type=Zip \
--architectures=x86_64 \
--role=arn:aws:iam::1234567890:role/your_lambda_aws_role \
--zip-file=fileb://lambda.zip \
--handler=Crambda
aws --region=us-west-1 \
lambda invoke \
--cli-binary-format raw-in-base64-out \
--function-name crystal_test01 /dev/stdout | jq .
[
"hello from Crystal: 1.10.1 - also wombats"
]
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
aws lambda delete-function \
--region=us-west-1 \
--function-name=crystal_test01