Sometimes you are buying something out of Brazil or worldwide using a credit card and thought "How much does it cost?" The price simulator helps you to simulate it test
- run tests:
lein test
- run lint-fix:
lein lint-fix
You must get your own api key on free currency and then export variable by env vars:
export API_KEY=YOURAPIKEY
WIP docker-compose up
$ lein uberjar
$ java -jar conversor-0.1.0-standalone.jar --currency=USB --amount=500
lein ring server-headless
lein run --currency=USD --amount=50
lein run --currency=EUR --amount=50
lein run --currency=ARS --amount=50
This project is serverless and ready to use on AWS Lambda to deploy and run it on Lambda, follow this steps:
Requirements
- You should have AWS CLI don't know how to install? See how on my youtube channel
- Create jar
lein uberjar
-
Create the role to run lambdas
a) trust-policy.json
echo '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }' > trust-policy.json
b) create this role with one name (our case, lambda-ex)
aws iam create-role --role-name lambda-ex --assume-role-policy-document file://trust-policy.json
c) You will see the json response and should copy the arn to use it further
{ "Role": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", ... }, ... "RoleName": "lambda-ex", "Path": "/", "Arn": "arn:aws:iam::5072812121311:role/lambda-ex" } }
-
Create your lambda (replace arn by your own)
aws lambda create-function \
--function-name price-simulator \
--handler conversor.core::handler \
--runtime java11 \
--memory 512 \
--timeout 10 \
--role arn:aws:iam::5072812121311:role/lambda-ex \
--zip-file fileb://./target/uberjar/conversor-0.1.0-SNAPSHOT-standalone.jar \
--region us-east-1
- Test it
aws lambda invoke \
--function-name price-simulator \
--payload '"300"' response.json \
--region=us-east-1
Done!
- tools.cli to get args
- clj-http to make http requests
- cheshire to handle JSON