코드 생로병사의 비밀
  • 코드 생로병사의 비밀
  • 시작하기
  • 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
  • 재귀적 삭제
  • 예시 #4
  • 버킷 존재 여부
  1. Amazon Q Developer
  2. AWS 서비스

S3 서비스

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


예시 #1

버킷 생성

일반적인 프롬프트

Given a string bucket_name
and an AWS session object
Then Create a bucket with the given name
and return the bucket object if successful
otherwise return None

Python 프롬프트

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

"""
Given a string bucket_name
and an AWS session object
Then Create a bucket with the given name
and return the bucket object if successful
otherwise return None

"""
Amazon Q Developer 제안
import boto3

def create_bucket(bucket_name, session):
    """
    :param bucket_name:
    :param session:
    :return:
    """
    s3 = session.resource('s3')
    try:
        bucket = s3.create_bucket(Bucket=bucket_name)
        return bucket
    except Exception as e:
        print(e)
        return None

예시 #2

버킷 리스트 가져오기

일반적인 프롬프트

Given an AWS session object
Then return a list of all buckets in the account if successful
otherwise return None

Python 프롬프트

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

"""
Given an AWS session object
Then return a list of all buckets in the account if successful
otherwise return None
"""
Amazon Q Developer 제안
def list_buckets(session):
    """
    :param session:
    :return:
    """
    s3 = session.resource('s3')
    try:
        return s3.buckets.all()
    except Exception as e:
        print(e)
        return None

예시 #3

재귀적 삭제

일반적인 프롬프트

Given a bucket Name 
And an AWS session object
Then recursively get list of all folders in the bucket
and delete all versions of objects folders
and delete the folders
and delete the bucket
and return True if successful
otherwise return False

Python 프롬프트

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

"""
Given a bucket Name 
And an AWS session object
Then recursively get list of all folders in the bucket
and delete all versions of objects folders
and delete the folders
and delete the bucket
and return True if successful
otherwise return False
"""
Amazon Q Developer 제안
def delete_bucket(bucket_name, session):
    """
    :param bucket_name:
    :param session:
    :return:
    """
    s3 = session.resource('s3')
    bucket = s3.Bucket(bucket_name)
    try:
        bucket.object_versions.delete()
        bucket.delete()
        return True
    except Exception as e:
        print(e)
        return False

예시 #4

버킷 존재 여부

일반적인 프롬프트

Given a bucket Name 
Then create a client object for s3
And Check if the bucket exists
and return True if it exists
otherwise return False

Python 프롬프트

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

"""
Given a bucket Name 
Then create a client object for s3
And Check if the bucket exists
and return True if it exists
otherwise return False
"""
Amazon Q Developer 제안
import boto3

def check_bucket_exists(bucket_name):
    """
    :param bucket_name:
    :return:
    """
    s3 = boto3.client('s3')
    try:
        s3.head_bucket(Bucket=bucket_name)
        return True
    except Exception as e:
        print(e)
        return False
PreviousAWS 서비스NextDynamoDB 서비스

Last updated 11 months ago