Skip to content

cylkdev/cloud_cache

Repository files navigation

CloudCache

TODO: Add description

Installation

If available in Hex, the package can be installed by adding cloud_cache to your list of dependencies in mix.exs:

def deps do
  [
    {:cloud_cache, "~> 0.1.0"}
  ]
end

Configuration

The following configuration is available:

if Mix.env() === :test do
  config :cloud_cache, CloudCache.Adapters.S3,
    auto_start: true,
    sandbox_enabled: true
else
  config :cloud_cache, CloudCache.Adapters.S3,
    auto_start: true,
    sandbox_enabled: false,
    retries: [
      max_attempts: 10,
      base_backoff_in_ms: 10,
      max_backoff_in_ms: 10_000
    ],
    access_key_id: [
      {:awscli, System.get_env("AWS_PROFILE", "default"), 30},
      {:awscli, System.get_env("AWS_PROFILE", "cloud_cache"), 30},
      {:system, "CLOUD_CACHE_AWS_ACCESS_KEY_ID"},
      {:system, "AWS_ACCESS_KEY_ID"},
      :instance_role
    ],
    secret_access_key: [
      {:awscli, System.get_env("AWS_PROFILE", "default"), 30},
      {:awscli, System.get_env("AWS_PROFILE", "cloud_cache"), 30},
      {:system, "CLOUD_CACHE_AWS_SECRET_ACCESS_KEY"},
      {:system, "AWS_SECRET_ACCESS_KEY"},
      :instance_role
    ]
end

Testing with LocalStack

LocalStack provides a fully functional local AWS cloud stack that you can use to test your application without connecting to real AWS services.

1. Quick Start with Environment Variables

If you just want to run a single test command against LocalStack, you can export temporary AWS credentials and override the endpoint URL:

export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_DEFAULT_REGION=us-west-1
aws --endpoint-url=http://localhost:4566 s3 ls
  • AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be set to any non-empty value. LocalStack recommends test.
  • AWS_DEFAULT_REGION can be any AWS region (e.g., us-west-1 or us-east-1).
  • --endpoint-url tells the AWS Command to talk to LocalStack instead of AWS.

Note: LocalStack requires the access key/secret to be set (even if they aren’t real), because its pre-signed URL signature validation checks for their presence.

2. Using a Custom AWS Profile for LocalStack

For a more seamless setup, you can configure a dedicated AWS Command profile for LocalStack.

Add this profile to ~/.aws/config:

[profile localstack]
endpoint_url = http://localhost:4566
region = us-west-1
output = json

Add matching credentials in ~/.aws/credentials:

[localstack]
aws_access_key_id = test
aws_secret_access_key = test

Now you can run commands without repeating environment variables or --endpoint-url.

For example:

aws --profile=localstack s3api create-bucket --bucket test --region us-west-1 --create-bucket-configuration LocationConstraint=us-west-1
aws s3 mb s3://test --profile localstack
aws s3 ls --profile localstack

Alternatively, you can also set the AWS_PROFILE=localstack environment variable, in which case the --profile localstack parameter can be omitted in the commands above.

For example:

export AWS_PROFILE=localstack
aws s3api create-bucket --bucket test --region us-west-1 --create-bucket-configuration LocationConstraint=us-west-1
aws s3 mb s3://test
aws s3 ls

3. Using awslocal

awslocal serves as a thin wrapper and a substitute for the standard aws command, enabling you to run AWS Command commands within the LocalStack environment without specifying the --endpoint-url parameter or a profile.

Install the awslocal command using the following command:

pip install awscli-local

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/cloud_cache.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages