# AWS in Python

AWS connections in the Dashboard and every boto3 service one attribute away, from S3 to CloudWatch.

Zato provides built-in support for connecting to AWS from your Python services. Connections are configured in the Dashboard, and your code accesses them through a simple, consistent API that covers every AWS service that [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) supports.

This approach means your services focus on business logic rather than credential handling, session management, or low-level SDK details. Zato handles all of that for you.

## Creating a connection {#creating-a-connection}

Open the Dashboard and go to `Cloud → AWS`. Create a new connection and fill in your account details.

| Field | Description |
| --- | --- |
| Name | Any name you want to reference the connection by in your services |
| Region | The AWS region to connect to, e.g. `us-east-1` or `eu-central-1` |
| Access key ID | The access key ID of the IAM user or role the connection authenticates as |
| Endpoint URL | Optional. Leave empty for AWS itself, or point it at an S3-compatible store or a local AWS simulator |
| Secret access key | Set it through the connection's "Change secret access key" option after the connection is created |

Once saved, the connection becomes available to all your services by its configured name.

## Basic usage {#basic-usage}

The connection is available through `self.aws`, and you reference it by the name you gave it in the Dashboard. Each AWS service is an attribute of the connection, so `conn.s3` is the S3 client, `conn.sqs` is the SQS client, and so on, for every service AWS offers.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class ListInvoiceFiles(Service):

    def handle(self):

        # Get the connection by the name configured in Dashboard
        conn = self.aws['My AWS']

        # List objects in a bucket
        response = conn.s3.list_objects_v2(Bucket='invoices')

        # Return the object names to the caller
        names = []
        for item in response['Contents']:
            names.append(item['Key'])

        self.response.payload = {'names': names}
```

## Everything boto3 supports {#everything-boto3-supports}

The per-service attributes are shorthand for boto3 clients - `conn.s3` is the same object as `conn.client('s3')`. For services whose names are not valid Python attributes, or when you prefer to be explicit, use `conn.client`. The higher-level resource API is available through `conn.resource`.

```python
# -*- coding: utf-8 -*-

# Zato
from zato.server.service import Service

class RunAnything(Service):

    def handle(self):

        conn = self.aws['My AWS']

        # Any service by name, same as boto3.client(...)
        athena = conn.client('athena')

        # The resource API too, same as boto3.resource(...)
        dynamodb = conn.resource('dynamodb')
        table = dynamodb.Table('customers')
```

Clients and resources are cached per connection, so repeated access is free.

## AWS services {#aws-services}

Each page below covers one of the most commonly integrated AWS services, with complete, working examples:

- **[Tutorial](https://zato.io/docs/dev/examples/cloud/aws/tutorial.html)** - start here if this is your first AWS connection
- **[S3](https://zato.io/docs/dev/examples/cloud/aws/s3.html)** - buckets, objects, presigned URLs
- **[EC2](https://zato.io/docs/dev/examples/cloud/aws/ec2.html)** - describe and manage instances
- **[SQS](https://zato.io/docs/dev/examples/cloud/aws/sqs.html)** - queues, sending and receiving messages
- **[SNS](https://zato.io/docs/dev/examples/cloud/aws/sns.html)** - topics, publishing, subscriptions
- **[DynamoDB](https://zato.io/docs/dev/examples/cloud/aws/dynamodb.html)** - tables, items, queries
- **[Lambda](https://zato.io/docs/dev/examples/cloud/aws/lambda.html)** - invoking functions
- **[CloudWatch](https://zato.io/docs/dev/examples/cloud/aws/cloudwatch.html)** - metrics and logs

## Learn more {#learn-more}

- [Development documentation](https://zato.io/docs/dev/) - The complete reference for writing services
- [Requests and responses](https://zato.io/docs/dev/request-response/) - What a service receives, what it returns and how both are structured
- [Integration examples](https://zato.io/docs/dev/examples/) - Ready-made code for the systems you are likely to connect to
- [IDE and debugging](https://zato.io/docs/dev/ide/) - Write services in the Dashboard or in your own editor
- [Data models](https://zato.io/docs/dev/model/) - Declare inputs and outputs and have them validated for you
- [In-depth API tutorial](https://zato.io/tutorials/main/01.html) - The full platform tutorial, from installation to production patterns
