Skip to main content

AWS utils for lambda

boto3version pythonversion

  • Wrapper for Boto3
  • Handles Exceptions gracefully and returns structured response
  • Can be used in lambda layers along with boto3 package

Install

pip install -U aws-utils-for-lambda

Request

import aws_utils
aws_utils.s3.get_object('bucket_name', 'test_data.json', output_format='dict')

Response (dict)

{
    'data': 'data',
    'success': True,
    'output_format': 'dict',
    'error': "ClientError",
    'error_message': 'error_message',
    'full_response': 'full_response',
    'short_traceback': 'short_traceback',
    'full_traceback': 'full_traceback'
}

How it works

AWS-boto-wrapper-2

Edit diagram link

Currently supported

  • S3
    • upload_file
    • get_object
  • DynamoDB
    • get_item
    • put_item

Example 1

Get S3 object - request:

import aws_utils
response = aws_utils.s3.get_object('bucket_name', 'test_data.json', output_format='dict')
print(response)

Get S3 object - response:

{
    'data': '{\n    "name": "name",\n    "age": "24",\n    "country": "India"\n}',
    'success': True,
    'output_format': 'dict',
    'error': None,
    'error_message': None,
    'full_response': {
        'ResponseMetadata': {
            'RequestId': 'xxxxxxxxxxxx',
            'HostId': 'xxxxxxxxxxxx',
            'HTTPStatusCode': 200,
            'HTTPHeaders': {
                'x-amz-id-2': 'xxxxxxxxxxxx',
                'x-amz-request-id': 'xxxxxxxxxxxx',
                'date': 'Sun, 26 May 2019 10:04:23 GMT',
                'last-modified': 'Sun, 26 May 2019 10:04:18 GMT',
                'etag': '"xxxxxxxxxxxx"',
                'accept-ranges': 'bytes',
                'content-type': 'application/json',
                'content-length': '65',
                'server': 'AmazonS3'
            },
            'RetryAttempts': 0
        },
        'AcceptRanges': 'bytes',
        'LastModified': datetime.datetime(2019, 5, 26, 10, 4, 18, tzinfo=tzutc()),
        'ContentLength': 65,
        'ETag': '"xxxxxxxxxxxx"',
        'ContentType': 'application/json',
        'Metadata': {},
        'Body': "<botocore.response.StreamingBodyat0x10591111>"
    },
    'short_traceback': None,
    'full_traceback': None
}

Example 2

Get S3 object - request:

import aws_utils
response = aws_utils.s3.get_object('bucket_name', 'test_data.json', output_format='dict')
print(response)

Get S3 object - response:

{
    'data': None,
    'success': False,
    'output_format': 'dict',
    'error': 'NoSuchKey',
    'error_message': 'An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.',
    'full_response': None,
    'short_traceback': ['  File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/aws_utils/s3.py" line 26, in get_object\n    full_response = s3.meta.client.get_object(Bucket=bucket, Key=file_path)\n',
                        '  File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n',
                        '  File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n'],
    'full_traceback': ['Traceback (most recent call last):\n',
                       '  File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/aws_utils/s3.py", line 26, in get_object\n    full_response = s3.meta.client.get_object(Bucket=bucket, Key=file_path)\n',
                       '  File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n',
                       '  File "/Users/nelsonsequiera/.pyenv/versions/3.7.2/envs/aws_utils_test/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n',
                       'botocore.errorfactory.NoSuchKey: An error occurred (NoSuchKey) when calling the GetObject operation: The specified key does not exist.\n']
}

Metadata

Release files for aws-utils-for-lambda 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for aws-utils-for-lambda 1.0.3
File Interpreter ABI Platform Actions
aws_utils_for_lambda-1.0.3-py3-none-any.whl Python 3 none any Details for aws_utils_for_lambda-1.0.3-py3-none-any.whl

Release files / aws_utils_for_lambda-1.0.3-py3-none-any.whl

Download URL aws_utils_for_lambda-1.0.3-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9834b773b8324e3807962ec865d07442b7e496acfe1c2dc239be009e6fff522f
BLAKE2b-256 checksum
How to use checksums
fecae3045f82a4c78e3d18dd8cabd8ce18787b97dce8e1de58f32da15126f383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

Security for aws-utils-for-lambda 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page