Skip to content

Commit

Permalink
Merge pull request #20 from keithrozario/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
keithrozario authored Apr 16, 2020
2 parents cfbc09b + dbcfacb commit 04221ff
Show file tree
Hide file tree
Showing 11 changed files with 334 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,6 @@ dmypy.json
# Terraform
.terraform/
*.tfstate

# serverless
.serverless/
296 changes: 270 additions & 26 deletions README.md

Large diffs are not rendered by default.

Binary file added docs/images/installed_package.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 12 additions & 6 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ Unlike other packages, _lambda_cache_ was designed to operate specifically withi

There are two general options to using it.

## Using the publicly available layer from Klayers
## Manual Installation

[Klayers](https://github.com/keithrozario/Klayers) is a project that publishes AWS Lambda Layers for public consumption. A Lambda layer is way to pre-package code for easy deployments into any Lambda function.
Because _lambda-cache_ is a pure python package, you can manually include it in your lambda function, like so:

You can 'install' _lambda_cache_ by simply including the latest layer arn in your lambda function.
$ pip install lambda-cache -t /path/to/function

Once installed you will see the following directory structure in your lambda function via the console:

![Installed Package](images/installed_package.png)

## Using Serverless Framework

Expand All @@ -18,10 +22,12 @@ simply ensure that _simple_lambda_cache_ is part of your `requirements.txt` file

$ pip install lambda-cache

## Using the publicly available layer from Klayers

[Klayers](https://github.com/keithrozario/Klayers) is a project that publishes AWS Lambda Layers for public consumption. A Lambda layer is way to pre-package code for easy deployments into any Lambda function.

You can 'install' _lambda_cache_ by simply including the latest layer arn in your lambda function.

## Manual Installation

Because _lambda_cache_ is a pure python package, you can also manually include it in your lambda function, like so:

$ pip install lambda-cache -t /path/to/function

15 changes: 13 additions & 2 deletions lambda_cache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
__all__ = ["cache", "get_entry"]
__version__ = "0.8.0"
# -*- coding: utf-8 -*-

"""
lambda-cache
~~~~~~~~~~~~
A python package for caching within AWS Lambda Functions
Full Documentation is at <https://lambda-cache.rtfd.io>.
:license: MIT, see LICENSE for more details.
"""

__version__ = "0.8.1"

from .ssm import cache, get_entry
from .secrets_manager import cache, get_entry
Expand Down
6 changes: 6 additions & 0 deletions lambda_cache/caching_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


def get_decorator(**kwargs):

"""
Args:
argument (string, list, dict) : argument to be passed to the missed function
Expand Down Expand Up @@ -34,6 +35,7 @@ def inner_function(event, context):


def get_value(**kwargs):

"""
returns value of check_cache.
"""
Expand All @@ -50,6 +52,7 @@ def check_cache(
send_details=False,
**kwargs
):

"""
Executes the caching logic, checks cache for entry
If entry doesn't exist, returns entry_value by calling the miss function with entry_name and var_name
Expand Down Expand Up @@ -97,6 +100,7 @@ def check_cache(


def get_entry_name(argument, entry_name):

"""
argument is either SSM Parameter, Secret in Secrets Manager or Key in S3 bucket:
SSM Parameter names can include only the following symbols and letters: a-zA-Z0-9_.-/
Expand Down Expand Up @@ -136,6 +140,7 @@ def get_entry_name(argument, entry_name):


def get_entry_age(entry_name):

"""
Args:
entry_name(string): Name of entry to get age for
Expand Down Expand Up @@ -180,6 +185,7 @@ def update_cache(entry_name, entry_value):


def get_entry_from_cache(entry_name):

"""
Gets entry value from the cache
Expand Down
20 changes: 17 additions & 3 deletions lambda_cache/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
class LambdaCacheError(Exception):
"""Base class for exceptions in this module."""

"""
Base class for exceptions in this module.
"""

pass


class ArgumentTypeNotSupportedError(LambdaCacheError):
"""Raised when Argument is not supported by the function."""

"""
Raised when Argument is not supported by the function.
"""

def __init__(self, message):
self.message = message
self.Code = "ArgumentTypeNotSupportedError"


class NoEntryNameError(LambdaCacheError):
"""Raised when No entry_name is provided."""

"""
Raised when No entry_name is provided.
"""

def __init__(self, message=False):
self.message = "No entry_name provided"
self.Code = "NoEntryNameError"


class InvalidS3UriError(LambdaCacheError):

"""
s3Uri provided in invalid format
"""

def __init__(self, invalid_uri):
self.message = f"Expected Valid s3uri of the form 's3://bucket-name/path/to/file', given: {invalid_uri}"
self.Code = "InvalidS3UriError"
5 changes: 3 additions & 2 deletions lambda_cache/s3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import boto3
from datetime import datetime, timezone

from .caching_logic import get_decorator, get_value, get_entry_name
from .exceptions import ArgumentTypeNotSupportedError, InvalidS3UriError
from .caching_logic import get_decorator, get_value
from .exceptions import InvalidS3UriError


def cache(
Expand Down Expand Up @@ -62,6 +62,7 @@ def get_entry(


def get_object_from_s3(**kwargs):

"""
Gets parameter value from the System manager Parameter store
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tool.poetry]
name = "lambda-cache"
version = "0.8.0"
version = "0.8.1"
description = "Python utility for simple caching in AWS Lambda functions"
authors = ["keithrozario <[email protected]>"]
documentation = "https://simple-lambda-cache.readthedocs.io/en/latest/"
repository = "https://github.com/keithrozario/simple_lambda_cache"
homepage = "https://github.com/keithrozario/simple_lambda_cache"
documentation = "https://lambda-cache.readthedocs.io/en/latest/"
repository = "https://github.com/keithrozario/lambda-cache"
homepage = "https://github.com/keithrozario/lambda-cache"
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down
18 changes: 4 additions & 14 deletions tests/acceptance_tests/_test_ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import boto3

from lambda_cache import ssm
from datetime import datetime

# this file is packaged in the lambda using serverless.yml
from variables_data import *
Expand Down Expand Up @@ -30,19 +31,8 @@ def multi_parameter_2(event, context):
client = boto3.client('ssm')
response = client.put_parameter(
Name=ssm_parameter,
Value='string',
Type='String'|'StringList'|'SecureString',
KeyId='string',
Overwrite=True|False,
AllowedPattern='string',
Tags=[
{
'Key': 'string',
'Value': 'string'
},
],
Tier='Standard'|'Advanced'|'Intelligent-Tiering',
Policies='string'
)
Value=datetime.now().isoformat(),
Type='String',
Overwrite=True)

return generic_return(message)
3 changes: 2 additions & 1 deletion tests/acceptance_tests/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ provider:
Action:
- ssm:GetParameter
- ssm:GetParameters
- ssm:PutParameter
Resource:
- Fn::Join:
- ":"
Expand Down Expand Up @@ -89,7 +90,7 @@ package:
- tests/**

functions:
single_handler:
acceptance_test:
handler: _test_ssm.multi_parameter_2
layers:
- arn:aws:lambda:ap-southeast-1:908645878701:layer:pylayers-python38-defaultlambda-cache:1
Expand Down

0 comments on commit 04221ff

Please sign in to comment.