본문 바로가기

PYTHON-BACK

#파이썬 24.09.25_AWS CloudFront 실습2

728x90

AWS CloudFront 실습

Amazon Poly 실습

  • https://aws.amazon.com/ko/polly/getting-started/
  • 설명서나 유튜브 영상을 이용, 다 영어로 되어있으니 ai를 통해서 번역해서 이용 또는 구글에서 translate.google.com에서 문서 선택해서 번역해서 이용
  • Amazon Polly는 텍스트를 생생한 음성으로 변환하는 클라우드 서비스 
  • 만들어진 문장을 텍스트 투 스피치로 다운로드 하거나 S3에 저장해서 사용할 수 있다.

Amazon Lex 실습

Amazon Rekognition 실습

Amazon Lightsail 실습

AWS Glue 작업과 Python을 사용하여 테스트 데이터 생성

AWS에서 제공하고 있는 python에서 사용하는 sdk amazon s3예제(boto3)

import io
import os
import uuid

import boto3
from boto3.s3.transfer import S3UploadFailedError
from botocore.exceptions import ClientError


def do_scenario(s3_resource):
    print("-" * 88)
    print("Welcome to the Amazon S3 getting started demo!")
    print("-" * 88)

    bucket_name = f"doc-example-bucket-{uuid.uuid4()}"
    bucket = s3_resource.Bucket(bucket_name)
    try:
        bucket.create(
            CreateBucketConfiguration={
                "LocationConstraint": s3_resource.meta.client.meta.region_name
            }
        )
        print(f"Created demo bucket named {bucket.name}.")
    except ClientError as err:
        print(f"Tried and failed to create demo bucket {bucket_name}.")
        print(f"\t{err.response['Error']['Code']}:{err.response['Error']['Message']}")
        print(f"\nCan't continue the demo without a bucket!")
        return

    file_name = None
    while file_name is None:
        file_name = input("\nEnter a file you want to upload to your bucket: ")
        if not os.path.exists(file_name):
            print(f"Couldn't find file {file_name}. Are you sure it exists?")
            file_name = None

    obj = bucket.Object(os.path.basename(file_name))
    try:
        obj.upload_file(file_name)
        print(
            f"Uploaded file {file_name} into bucket {bucket.name} with key {obj.key}."
        )
    except S3UploadFailedError as err:
        print(f"Couldn't upload file {file_name} to {bucket.name}.")
        print(f"\t{err}")

    answer = input(f"\nDo you want to download {obj.key} into memory (y/n)? ")
    if answer.lower() == "y":
        data = io.BytesIO()
        try:
            obj.download_fileobj(data)
            data.seek(0)
            print(f"Got your object. Here are the first 20 bytes:\n")
            print(f"\t{data.read(20)}")
        except ClientError as err:
            print(f"Couldn't download {obj.key}.")
            print(
                f"\t{err.response['Error']['Code']}:{err.response['Error']['Message']}"
            )

    answer = input(
        f"\nDo you want to copy {obj.key} to a subfolder in your bucket (y/n)? "
    )
    if answer.lower() == "y":
        dest_obj = bucket.Object(f"demo-folder/{obj.key}")
        try:
            dest_obj.copy({"Bucket": bucket.name, "Key": obj.key})
            print(f"Copied {obj.key} to {dest_obj.key}.")
        except ClientError as err:
            print(f"Couldn't copy {obj.key} to {dest_obj.key}.")
            print(
                f"\t{err.response['Error']['Code']}:{err.response['Error']['Message']}"
            )

    print("\nYour bucket contains the following objects:")
    try:
        for o in bucket.objects.all():
            print(f"\t{o.key}")
    except ClientError as err:
        print(f"Couldn't list the objects in bucket {bucket.name}.")
        print(f"\t{err.response['Error']['Code']}:{err.response['Error']['Message']}")

    answer = input(
        "\nDo you want to delete all of the objects as well as the bucket (y/n)? "
    )
    if answer.lower() == "y":
        try:
            bucket.objects.delete()
            bucket.delete()
            print(f"Emptied and deleted bucket {bucket.name}.\n")
        except ClientError as err:
            print(f"Couldn't empty and delete bucket {bucket.name}.")
            print(
                f"\t{err.response['Error']['Code']}:{err.response['Error']['Message']}"
            )

    print("Thanks for watching!")
    print("-" * 88)


if __name__ == "__main__": # 프로그램 진입점, 이게 없음 모듈로만 사용, 있으면 실행으로도 사용 가능해짐
    do_scenario(boto3.resource("s3"))
 

 이런식으로 진행하게 되면 기존에 만들었던 bucket에

  • 문제에서 나온 순서를 토대로 배열을 만들면
  • 버킷을 만들고 버킷에 파일을 업로드합
  • 버킷에서 객체를 다운로드
  • 버킷의 하위 폴더에 객체를 복사
  • 버킷의 객체를 나열
  • 버킷 객체와 버킷을 삭제
  • 동작을 진행하게 된다.

https://github.com/Python-Backend-Team3/Team-TIL/blob/main/9.19%20~%209.30%20%ED%9A%8C%EA%B3%A0/2024-09-26%20-%20%EC%A7%80%EC%9B%85.md

 

Team-TIL/9.19 ~ 9.30 회고/2024-09-26 - 지웅.md at main · Python-Backend-Team3/Team-TIL

Today Learned repository. Contribute to Python-Backend-Team3/Team-TIL development by creating an account on GitHub.

github.com

<오늘의 회고>

728x90