Skip to main content

AWS service utilities for Lambda functions

Project description

Astromech - AWS Service Utilities for Lambda Functions

Astromech is a collection of utilities that I found myself copying all over my lambda functions and serverless projects. For the sake of DRYing up my code, I collected them in a single library.

Service Clients

Astromech implements lazy-initialization for Boto3 service clients:

For each service, there is a global client variable that gets reused between invocations of the labmda function container. Code that want access to the client achieves this by using a client() function that initializes it if necessary.

Code example:

from astromech import s3, dynamodb

s3.client().get_object(Bucket=..., Key=...)
dynamodb.table().get_item(Key=...)

LocalStack Support Made Easy

The service client initialization functions, look for the environment variable LOCALSTACK_[SERVICE]_URL (for example, LOCALSTACK_S3_URL). If it finds one, then it uses its value as the endpoint_url for the Boto3 client function.

All you have to do to run tests with LocalStack is to set these variables in your local environment. No changes to the code are necessary. Naturally, this works with any other downloadable version of AWS services, like DynamoDB local.

Utility Functions

There are a few utility functions in each service. These usually save 2-3 lines of boilerplate code. Not a lot, but for very common functionality that is repeated all across the code base, it becomes worthwhile.

For example, to check if an object exists on S3, you have to send a head_object request and catch the exception if it doesn't exist. With astromech.s3 you just call exists(bucket, key), much like you would do with a local file.

Why "Astromech"?

In the Star Wars universe, astromech is a type of utility droid, the most famous of which (whom?) is R2-D2.

Read more on Wookiepedia.

R2-series astromech droids

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astromech-0.5.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

astromech-0.5.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file astromech-0.5.0.tar.gz.

File metadata

  • Download URL: astromech-0.5.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for astromech-0.5.0.tar.gz
Algorithm Hash digest
SHA256 504ed50c4375a109f88c45b79cb86ce00d66572c2c37a258143523dcee8f3c42
MD5 929ed9b6a32b2fa3295d7546456831f7
BLAKE2b-256 bf743b67e9e85949ffd93ba95a0bac0e6cc8ff86f39f16ca82baf7c519f7bed6

See more details on using hashes here.

File details

Details for the file astromech-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: astromech-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for astromech-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84c651c0268eda0f12186a1fecd7c79b1ddb4a188baddeaafd451f975e2c11ef
MD5 b6a86dde7d50fdecd92d635c0dc24d76
BLAKE2b-256 b65ad46850199408d1435daea6e6f6afe31324e772b423e098459e5d6a01eedc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page