# Your first AWS integration

First AWS connection, first service and the three ways to reach any AWS API through boto3.

This tutorial shows each step of your first AWS integration with Zato - from creating the connection in the Dashboard to invoking any AWS API from a Python service.

## Step 1 - Create the connection {#step-1-create-the-connection}

Open the Dashboard and go to `Cloud → AWS`. Click "Create a new connection" and fill in the form:

| Field | Value |
| --- | --- |
| Name | `My AWS` |
| Region | The region you work in, e.g. `us-east-1` |
| Access key ID | The access key ID of your IAM user |
| Endpoint URL | Leave it empty for AWS itself |

After the connection is created, click "Change secret access key" next to it and enter the secret access key that pairs with your access key ID.

You can now click "Ping" to confirm that the credentials work - it calls [STS GetCallerIdentity](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html), which requires no permissions beyond the credentials themselves.

## Step 2 - Write the first service {#step-2-write-the-first-service}

The connection is available in every service through `self.aws`, referenced by name. Let's list your S3 buckets:

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

# Zato
from zato.server.service import Service

class ListBuckets(Service):

    def handle(self):

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

        # Call S3
        response = conn.s3.list_buckets()

        # Extract the names
        names = []
        for bucket in response['Buckets']:
            names.append(bucket['Name'])

        # Return them to the caller
        self.response.payload = {'buckets': names}
```

Hot-deploy the service and invoke it - the response will be a list of your bucket names:

```json
{"buckets": ["invoices", "reports", "backups"]}
```

## Step 3 - Understand the API {#step-3-understand-the-api}

There are three ways to reach an AWS service through the connection, and all of them go through the same underlying boto3 session:

**Attribute access** - each AWS service is an attribute of the connection. This is the most convenient form and covers the common cases:

```python
conn = self.aws['My AWS']

conn.s3.list_buckets()
conn.sqs.list_queues()
conn.ec2.describe_instances()
```

**Explicit clients** - `conn.client(name)` is the same as `boto3.client(name)`. Use it for services whose names are not valid Python attributes, such as `lambda`, or when you prefer to be explicit:

```python
conn = self.aws['My AWS']

aws_lambda = conn.client('lambda')
aws_lambda.invoke(FunctionName='process-order')
```

**Resources** - `conn.resource(name)` is the same as `boto3.resource(name)`, the higher-level object-oriented API that some services offer:

```python
conn = self.aws['My AWS']

dynamodb = conn.resource('dynamodb')
table = dynamodb.Table('customers')
table.put_item(Item={'customer_id': 'abc-123', 'name': 'Jane'})
```

Clients and resources are cached, so accessing `conn.s3` repeatedly always returns the same object, and `conn.s3` is the same object as `conn.client('s3')`.

## Step 4 - Explore the services {#step-4-explore-the-services}

With the connection in place, every AWS API is one attribute away. The pages below cover the most common integrations with complete examples:

- **[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

## More resources {#more-resources}

- [AWS integrations overview](https://zato.io/docs/dev/examples/cloud/aws/index.html)
- [boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html)

## 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
