> For the complete documentation index, see [llms.txt](https://docs.gdf.ai/gdf-full-stack-engineering/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gdf.ai/gdf-full-stack-engineering/subject-knowledge-areas/integration/connecting-cloud-infrastructure-aws.md).

# Connecting Cloud Infrastructure (AWS)

## Summary

Connecting multiple cloud services in AWS, such as API Gateway, AWS Lambda, DynamoDB, and S3, is essential for building scalable and efficient applications. Generative AI can provide guidance and code snippets for integrating these services in the context of a bicycle rental application.

Example: A developer is building a bicycle rental app and needs to connect their API Gateway to AWS Lambda running an Express Node.js function, which communicates with a DynamoDB table and an S3 bucket.

### Prompt

{% code overflow="wrap" %}

```
Provide an example of how to connect an API Gateway to an AWS Lambda function running an Express Node.js app, which interacts with a DynamoDB table and an S3 bucket in the context of a bicycle rental application.
```

{% endcode %}

### Response

{% code overflow="wrap" %}

```javascript
// Required dependencies: aws-sdk, aws-serverless-express
const AWS = require('aws-sdk');
const express = require('express');
const serverless = require('aws-serverless-express');
const { v4: uuidv4 } = require('uuid');

const app = express();
app.use(express.json());

const s3 = new AWS.S3();
const dynamodb = new AWS.DynamoDB.DocumentClient();
const BUCKET_NAME = process.env.BUCKET_NAME;
const TABLE_NAME = process.env.TABLE_NAME;

// Upload bicycle image to S3
app.post('/bicycle-image', async (req, res) => {
  const imageBuffer = Buffer.from(req.body.image, 'base64');
  const key = uuidv4() + '.png';

  const params = {
    Bucket: BUCKET_NAME,
    Key: key,
    Body: imageBuffer,
    ContentType: 'image/png',
  };

  try {
    await s3.upload(params).promise();
    res.json({ imageUrl: `https://${BUCKET_NAME}.s3.amazonaws.com/${key}` });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

// Add bicycle to DynamoDB
app.post('/bicycle', async (req, res) => {
  const bicycle = req.body;

  const params = {
    TableName: TABLE_NAME,
    Item: bicycle,
  };

  try {
    await dynamodb.put(params).promise();
    res.json({ message: 'Bicycle added successfully' });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

// Get bicycles from DynamoDB
app.get('/bicycles', async (req, res) => {
  const params = {
    TableName: TABLE_NAME,
  };

  try {
    const result = await dynamodb.scan(params).promise();
    res.json(result.Items);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

const server = serverless.createServer(app);
exports.handler = (event, context) => {
  serverless.proxy(server, event, context);
};
```

{% endcode %}

## Discussion

Using generative AI to connect and integrate multiple cloud resources offers several advantages and challenges:

Pros:

1. Accelerates the development process by providing ready-to-use code snippets for integrating multiple AWS services.
2. Offers guidance on best practices for connecting cloud resources in a scalable and efficient manner.
3. Helps developers learn about and navigate the complexities of cloud services.

Cons:

1. Generated code may require further customization to suit specific project requirements or security policies.
2. May not cover all possible integrations or edge cases, requiring developers to adapt the code to their needs.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gdf.ai/gdf-full-stack-engineering/subject-knowledge-areas/integration/connecting-cloud-infrastructure-aws.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
