코드 생로병사의 비밀
  • 코드 생로병사의 비밀
  • 시작하기
  • Amazon Q Business
    • Amazon Q Business 애플리케이션 설정
    • 데이터 소스 구성
      • 웹 크롤러 데이터 소스 커넥터 활용하기
      • 문서 업로드
      • Amazon S3 데이터 소스 커넥터 구성
    • 관리자 컨트롤 및 가드레일 구성
      • 글로벌 컨트롤 구성하기
      • 주제 수준 컨트롤 구성
  • Amazon Q Developer
    • Amazon Q Developer 애플리케이션 로그인
    • 프롬프트 유형
      • 함수명 프롬프트
      • 한 줄 주석
      • 한 줄 프롬프트
      • 여러 줄 주석
      • 여러 줄 프롬프트
      • 변수명 기준
      • 고려 사항
    • 알고리즘 생성
      • 버블 정렬
      • 합병 정렬
    • 정규표현식
      • 정규 표현식 - 이메일
      • 정규 표현식 - 휴대폰
      • 정규 표현식 - 커스텀 표현식
    • 클래스 생성
      • Folder 클래스
      • User 클래스
      • 객체 지향 프로그래밍(OOP): 다형성 & 상속
    • SQL
      • SQL - Users
      • SQL - E-commerce Schema
    • 가짜 데이터 생성
      • 가짜 데이터 - 주가
      • Faker 패키지를 활용한 가짜 유저
    • AWS 서비스
      • S3 서비스
      • DynamoDB 서비스
      • SQS 서비스
Powered by GitBook
On this page
  • 예시 #1
  • 큐 생성
  • 예시 #2
  • 큐 생성
  • 예시 #3
  • Item 추가
  • 예시 #4
  • Item 가져오기
  1. Amazon Q Developer
  2. AWS 서비스

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
"""
Amazon Q Developer 제안
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
PreviousDynamoDB 서비스

Last updated 11 months ago