This is bare-bones, lacking everything extra and most notably:
- No https:// for OpenFaaS and Nomad (TODO: maybe use an API Gateway?)
- Terraform remote state locking (use e.g. terragrunt)
Forked and fixed from terraform-aws-open-faas-nomad, faas.hcl
using faas-nomad/nomad_job_files/faas.hcl as the base.
export AWS_ACCESS_KEY_ID={{aws_access_key_id}}
export AWS_SECRET_ACCESS_KEY={{aws_secret_access_key}}
export AWS_SESSION_TOKEN={{aws_session_token}}
Tip: Prefer aws-vault to store
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
in some keyring
(on OS X, Linux distros).
brew install faas-cli
brew install nomad
brew install terraform
Tip: On GNU\Linux, try linuxbrew.
terraform init
terraform plan
terraform apply
export NOMAD_ADDR=$(terraform output nomad_endpoint)
nomad run faas.hcl
export OPENFAAS_URL=$(terraform output openfaas_endpoint)
cd functions
I already committed this to the repository:
faas-cli new -lang python3 pyfunc
Change image
in .yml
to include username for DockerHub, or prepend the private Docker registry url.
Argument -lang
can be dockerfile
, to run any Docker container as a function:
faas-cli build -f pyfunc.yml
faas-cli push -f pyfunc.yml
Make the image public in DockerHub, to get OpenFaaS to fetch it. (TODO: have some privacy)
faas-cli deploy --gateway=$OPENFAAS_URL -f pyfunc.yml
curl -X POST "${OPENFAAS_URL}/function/pyfunc" -d "💣"
open $OPENFAAS_URL
nomad ui