# SQS 서비스

Amazon Q Developer를 사용해 DynamoDB 서비스를 위한 코드를 생성합니다.

***

## 예시 #1

### 큐 생성

#### 일반적인 프롬프트

```bash
create an sqs client and
create a queue if it does not exist
otherwise return the queue
```

#### Python 프롬프트

VSCode에서 파일을 생성하고 이름을 `sqs.py`로 지정하고 다음 코드를 입력합니다.

```bash
"""
create an sqs client and
create a queue if it does not exist
otherwise return the queue

"""
```

<details>

<summary>Amazon Q Developer 제안</summary>

```bash
import boto3

def create_queue(queue_name):
    sqs = boto3.resource('sqs')
    try:
        queue = sqs.create_queue(QueueName=queue_name)
        return queue
    except Exception as e:
        print(e)
        return None
```

</details>

***

## 예시 #2

### 큐 생성

#### 일반적인 프롬프트

```bash
Given a queue name, and client object
create a function to check if a queue exists
if the queue exists, return the queue
if the queue does not exist, return None
```

#### Python 프롬프트

```bash
"""
Given a queue name, and client object
create a function to check if a queue exists
if the queue exists, return the queue
if the queue does not exist, return None
"""
```

<details>

<summary>Amazon Q Developer 제안</summary>

```bash
def check_queue(queue_name):
    sqs = boto3.resource('sqs')
    try:
        queue = sqs.get_queue_by_name(QueueName=queue_name)
        return queue
    except Exception as e:
        print(e)
        return None
    
```

</details>

***

## 예시 #3

### Item 추가

#### 일반적인 프롬프트

```bash
Given a queue name, and client object
create a function to put an item on an AWS SQS queue
check to see if the queue exists
if the queue does not exist, create it
if the queue does exist, use the queue object

if successful, return True
if unsuccessful, return False
```

#### Python 프롬프트

```bash
"""
Given a queue name, and client object
create a function to put an item on an AWS SQS queue
check to see if the queue exists
if the queue does not exist, create it
if the queue does exist, use the queue object

if successful, return True
if unsuccessful, return False
"""
```

<details>

<summary>Amazon Q Developer 제안</summary>

```bash
def put_item_on_queue(queue_name, item):
    sqs = boto3.resource('sqs')
    queue = check_queue(queue_name)
    if queue is None:
        queue = create_queue(queue_name)
    if queue is not None:
        queue.send_message(MessageBody=item)
        return True
    else:
        return False
```

</details>

***

## 예시 #4

### Item 가져오기

#### 일반적인 프롬프트

```bash
Given a queue name, and client object
create a function to get an item from an AWS SQS queue
check to see if the queue exists

if successful, return True
if unsuccessful, return False

```

#### Python 프롬프트

```bash
"""

Given a queue name, and client object
create a function to get an item from an AWS SQS queue
check to see if the queue exists

if successful, return True
if unsuccessful, return False
"""
```

<details>

<summary>Amazon Q Developer 제안</summary>

```bash
def get_item_from_queue(queue_name):
    sqs = boto3.resource('sqs')
    queue = check_queue(queue_name)
    if queue is not None:
        response = queue.receive_messages(MessageAttributeNames=['All'])
        for message in response:
            print(message.body)
            message.delete()
        return True
    else:
        return False
```

</details>


---

# Agent Instructions: 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:

```
GET https://bangshinchul.gitbook.io/amazon-q/amazon-q-developer/aws/sqs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
