Manual deployments

Building and deploying using Docker

You can build and deploy your application from anywhere where docker can be run.

The following is an example of how you can accomplish this in your development environment.

  1. Create a file in the root of your project:

    #!/usr/bin/env bash
    # We need a requirements.txt file for the dependencies.
    # This step is not required if you have a requirements.txt file already.
    poetry export -f requirements.txt -o requirements.txt --without-hashes
    # Build and deploy the application.
    pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_build_and_deploy
    # Do you have migrations or additional commmands?
    # Then add --wait to the deploy command:
    # pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_build_and_deploy --wait
    # pipx run --spec "pd_aws_lambda[deploy]~=1.0" pd_run -- python3 migrate

  2. Make the file executable:

    chmod +x

  3. Create an environment variables file to hold credentials to PythonDeploy:

    # .env.pd_deploy
    # Do not commit this file to your git repository.

  4. Run with docker:

    # Set to your python version.
    # Build and deploy!
    docker \
        run --rm -v "${PWD}:/pd_app" -w /pd_app \
        --env-file .env.pd_deploy \
        lambci/lambda:build-python${PD_PYTHON_VERSION} ./

This will build your dependencies, package your dependencies and you application code, and deploy it to AWS. You can now visit your new site using the URL provided to you in your application's dashboard.

Testing your dependencies

To test if your dependencies are compatible with AWS Lambda environments you can use the LambdaCI Docker images provided by Amazon:

  • lambci/lambda:build-python3.7
  • lambci/lambda:build-python3.8

One way of testing if your dependencies compile and install successfully is to install them directly in the docker images:

# Set to your python version.
# Install your dependencies!
docker \
    run --rm -v "${PWD}:/pd_app" -w /pd_app \
    lambci/lambda:build-python${PD_PYTHON_VERSION} pip install -r requirements.txt

If you get no errors, then you should be fine.

Something missing? → [email protected]