diff --git a/Dockerfile b/Dockerfile index 57eb460c..0c02899c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,9 @@ ARG runtime RUN mkdir -p /build/python/lib/$runtime/site-packages WORKDIR /build -# Install dependencies -COPY requirements.txt requirements.txt -RUN pip install -r requirements.txt -t ./python/lib/$runtime/site-packages - -# Install datadog_lambda -COPY datadog_lambda ./python/lib/$runtime/site-packages/datadog_lambda +# Install datadog_lambda and dependencies from local +COPY . . +RUN pip install . -t ./python/lib/$runtime/site-packages # Remove *.pyc files RUN find ./python/lib/$runtime/site-packages -name \*.pyc -delete \ No newline at end of file diff --git a/README.md b/README.md index 97d66406..3ed556b9 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,15 @@ Replace `` with the AWS region where your Lambda function is publish arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Python37:1 ``` +### PyPI + +When developing your Lambda function locally where AWS Layer doesn't work, the Datadog Lambda layer can be installed from [PyPI](https://pypi.org/project/datadog-lambda/) by `pip install datadog-lambda` or adding `datadog-lambda` to your project's `requirements.txt`. + +The minor version of the `datadog-lambda` package always match the layer version. E.g., datadog-lambda v0.5.0 matches the content in layer version 5. + + +### Environment Variables + The Datadog API must be defined as an environment variable via [AWS CLI](https://docs.aws.amazon.com/lambda/latest/dg/env_variables.html) or [Serverless Framework](https://serverless-stack.com/chapters/serverless-environment-variables.html): * DD_API_KEY or DD_KMS_API_KEY (if encrypted by KMS) diff --git a/datadog_lambda/__init__.py b/datadog_lambda/__init__.py index 469a5047..ae82c8b8 100644 --- a/datadog_lambda/__init__.py +++ b/datadog_lambda/__init__.py @@ -1 +1,3 @@ -__version__ = "4" +# The minor version corresponds to the Lambda layer version. +# E.g.,, version 0.5.0 gets packaged into layer version 5. +__version__ = '0.5.0' diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index fd6dca98..00000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -nose2==0.9.1 -flake8==3.7.7 -requests==2.21.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 21d3f0c9..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -aws-xray-sdk==2.4.2 -datadog==0.28.0 -wrapt==1.11.1 -setuptools==40.8.0 -boto3==1.9.160 \ No newline at end of file diff --git a/scripts/pypi.sh b/scripts/pypi.sh new file mode 100755 index 00000000..dd1be156 --- /dev/null +++ b/scripts/pypi.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Unless explicitly stated otherwise all files in this repository are licensed +# under the Apache License Version 2.0. +# This product includes software developed at Datadog (https://www.datadoghq.com/). +# Copyright 2019 Datadog, Inc. + +# Builds the lambda layer and upload to Pypi +set -e + +# Clear previously built distributions +if [ -d "dist" ]; then + echo "Removing folder 'dist' to clear previously built distributions" + rm -rf dist; +fi + +# Install build tools +pip install --upgrade setuptools wheel twine + +# Build distributions +python setup.py sdist bdist_wheel + +# Upload distributions +python -m twine upload dist/* diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 8f9460b8..c8643de7 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -15,7 +15,6 @@ do echo "Running tests against python${python_version}" docker build -t datadog-lambda-layer-python-test:$python_version \ -f tests/Dockerfile . \ - --quiet \ --build-arg python_version=$python_version docker run -v `pwd`:/datadog-lambda-layer-python \ -w /datadog-lambda-layer-python \ diff --git a/setup.py b/setup.py index f71ba5ce..bb1b8a71 100644 --- a/setup.py +++ b/setup.py @@ -2,14 +2,16 @@ from os import path from io import open +from datadog_lambda import __version__ + here = path.abspath(path.dirname(__file__)) with open(path.join(here, 'README.md'), encoding='utf-8') as f: long_description = f.read() setup( - name='ddlambda', - version='0.2.0', + name='datadog_lambda', + version=__version__, description='The Datadog AWS Lambda Layer', long_description=long_description, long_description_content_type='text/markdown', @@ -24,4 +26,18 @@ keywords='datadog aws lambda layer', packages=['datadog_lambda'], python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4', + install_requires=[ + 'aws-xray-sdk==2.4.2', + 'datadog==0.28.0', + 'wrapt==1.11.1', + 'setuptools==40.8.0', + 'boto3==1.9.160' + ], + extras_require={ + 'dev': [ + 'nose2==0.9.1', + 'flake8==3.7.7', + 'requests==2.21.0' + ] + } ) diff --git a/tests/Dockerfile b/tests/Dockerfile index 1fd2c4df..218fe3b2 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -3,8 +3,9 @@ FROM python:$python_version ENV PYTHONDONTWRITEBYTECODE True -COPY .flake8 .flake8 -COPY requirements.txt requirements.txt -COPY requirements-dev.txt requirements-dev.txt -RUN pip install -r requirements.txt -RUN pip install -r requirements-dev.txt \ No newline at end of file +RUN mkdir -p /test +WORKDIR /test + +# Install datadog-lambda with dev dependencies from local +COPY . . +RUN pip install .[dev] \ No newline at end of file