mix lambda.build (Mayfly v0.1.0)

View Source

A Mix task for building AWS Lambda deployment packages for Elixir applications.

This task creates a deployment package for AWS Lambda, including:

  • Building a release using mix release
  • Creating a bootstrap script
  • Optionally building in a Docker container
  • Optionally creating a ZIP archive for deployment

Usage

mix lambda.build [options]

Options

--zip, -z      - Create a ZIP file for deployment
--outdir, -o   - Specify the output directory (default: current directory)
--docker, -d   - Build using Docker (useful for cross-platform compatibility)
--help, -h     - Print this help message

Examples

# Build a release
mix lambda.build

# Build a release and create a ZIP file
mix lambda.build --zip

# Build using Docker and create a ZIP file
mix lambda.build --docker --zip

# Specify an output directory
mix lambda.build --zip --outdir ./deploy

Summary

Functions

Generates the content for the bootstrap script.

Builds the release using mix release.

Creates the bootstrap file.

Creates a ZIP archive if requested.

Handles Docker build if requested.

Parses and validates command line arguments.

Prints help information.

Prints a summary of the build process.

Restores the original environment.

Runs the Lambda build task.

Runs a system command and handles the result.

Sets up the build environment.

Functions

bootstrap_content(project_name)

@spec bootstrap_content(atom()) :: String.t()

Generates the content for the bootstrap script.

build_release()

@spec build_release() :: :ok | {:error, String.t()}

Builds the release using mix release.

Returns :ok if successful.

create_bootstrap(opts)

@spec create_bootstrap(keyword()) :: {:ok, String.t()} | {:error, String.t()}

Creates the bootstrap file.

Returns {:ok, bootstrap_path} if successful.

create_zip_archive(opts, bootstrap_path)

@spec create_zip_archive(
  keyword(),
  String.t()
) :: :ok | {:error, String.t()}

Creates a ZIP archive if requested.

Returns :ok if successful or if ZIP creation was not requested.

handle_docker_build(opts, bootstrap_path)

@spec handle_docker_build(
  keyword(),
  String.t()
) :: :ok | {:error, String.t()}

Handles Docker build if requested.

Returns :ok if successful or if Docker build was not requested.

parse_and_validate_args(args)

@spec parse_and_validate_args([String.t()]) ::
  {:ok, keyword()} | {:halt, :help} | {:error, String.t()}

Parses and validates command line arguments.

Returns {:ok, opts} if successful, {:halt, :help} if help was requested, or {:error, reason} if validation fails.

restore_environment(old_mix_env)

@spec restore_environment(String.t() | nil) :: :ok

Restores the original environment.

Returns :ok if successful.

run(args)

@spec run([String.t()]) :: any()

Runs the Lambda build task.

This is the main entry point for the mix task, orchestrating the build process.

run_command(cmd, args)

@spec run_command(String.t(), [String.t()]) ::
  {:ok, String.t()} | {:error, String.t()}

Runs a system command and handles the result.

Returns {:ok, output} if successful, or {:error, reason} if the command fails.

setup_environment()

@spec setup_environment() :: String.t() | nil

Sets up the build environment.

Sets MIX_ENV to "lambda" and returns the original value.