SQS 서비스
Amazon Q Developer를 사용해 DynamoDB 서비스를 위한 코드를 생성합니다.
예시 #1
큐 생성
일반적인 프롬프트
create an sqs client and
create a queue if it does not exist
otherwise return the queue
Python 프롬프트
VSCode에서 파일을 생성하고 이름을 sqs.py
로 지정하고 다음 코드를 입력합니다.
"""
create an sqs client and
create a queue if it does not exist
otherwise return the queue
"""
Amazon Q Developer 제안
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
예시 #2
큐 생성
일반적인 프롬프트
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 프롬프트
"""
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
"""
Amazon Q Developer 제안
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
예시 #3
Item 추가
일반적인 프롬프트
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 프롬프트
"""
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
"""
Amazon Q Developer 제안
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
예시 #4
Item 가져오기
일반적인 프롬프트
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 프롬프트
"""
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
"""
Last updated