This creates a lambda handler that can handle preset events, which are passed in, with an action
variable that maps to a specific enum Action
. The event also includes parameters with the coin to process and an amount.
How does add funds work?
- Adds funds from your connected bank account to Coinbase. It will add enough funds for the buy amounf
How does buy work?
- Adds funds from your connected bank account to Coinbase. It will add enough funds for the daily buy amount
- Waits 15 minutes for funds to clear
- Buys the coin you indicated (COIN_TO_BUY) for the daily buy amount
docker build . -t crypto-dca
docker run --rm -p 8080:8080 crypto-dca
aws --profile personal lambda invoke --region us-east-1 --endpoint http://localhost:8080 --no-sign-request --function-name function --cli-binary-format raw-in-base64-out --payload '{"a": "b"}' output.txt
- Login to ECR (you may have to do this again to re-authenticate)
aws --profile personal ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin {REPLACE_WITH_AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com
- Create a new repository in ECR to store the Lambda function
aws --profile personal ecr create-repository --repository-name crypto-dca --image-scanning-configuration scanOnPush=true
export DOCKER_REGISTRY={AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com && make docker_build_and_push
- Then make sure to hit the button "Deploy new image" on the Lambda console
OR
docker build . -t crypto-dca
ormake build
docker tag crypto-dca {REPLACE_WITH_AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/crypto-dca:latest
ormake tag
docker push {REPLACE_WITH_AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/crypto-dca:latest
- We'll use an EventBridge (CloudWatch Events) as a trigger. Here are links to the triggers: -- https://us-east-1.console.aws.amazon.com/scheduler/home?region=us-east-1#schedules/default/sell-coins-weekly
- Create some test events. Here is an AddFunds event
{
"action": "addFunds",
"coin": "ETH",
"amount": 40
}
- Here is a BuyEvent for ETH
{
"action": "buyCoins",
"coin": "ETH",
"amount": 40
}
-- Here is a SellEvent for BTC
{
"action": "sellCoins",
"coin": "BTC",
"amount": 100
}
- Install docker
- Build docker images:
docker build . -t crypto-dca
- Run docker image:
docker run -p 49160:8080 -d crypto-dca
- or
docker run -p 9000:8080 -d crypto-dca
- or
- Debugging
- List containers (with container id) -
docker ps
- Show logs -
docker logs [container id]
- List containers (with container id) -
- To enter the machine:
docker exec -it [container id] /bin/bash
- Kill docker image:
docker kill [container id]