미리 서명된 URL을 통해 객체 공유
미리 서명된 URL을 사용하여 다른 사람이 Amazon S3 버킷에 객체를 업로드하도록 허용할 수 있습니다. 미리 서명된 URL을 사용하면 상대방에게 AWS 보안 자격 증명이나 권한이 없어도 업로드할 수 있습니다. 미리 서명된 URL은 이를 생성하는 사용자의 권한에 따라 제한됩니다. 즉, 객체를 업로드하기 위해 미리 서명된 URL을 수신하는 경우, URL의 생성자가 해당 객체를 업로드하는 데 필요한 권한을 보유하는 경우에만 객체를 업로드할 수 있습니다.
사용자가 URL을 사용하여 객체를 업로드하는 경우 Amazon S3는 지정된 버킷에 객체를 생성합니다. 미리 서명된 URL에 지정된 것과 동일한 키를 사용하는 객체가 이미 버킷에 있다면 Amazon S3는 업로드된 객체로 기존 객체를 바꿉니다. 업로드 후에는 버킷 소유자가 객체를 소유하게 됩니다.
미리 서명된 URL에 대한 일반적인 내용은 미리 서명된 URL을 통해 객체 다운로드 및 업로드 섹션을 참조하십시오.
AWS Explorer for Visual Studio를 사용하여 코드를 작성할 필요 없이 객체 업로드를 위해 미리 서명된 URL을 만들 수 있습니다. AWS SDK를 사용하여 프로그래밍 방식으로 미리 서명된 URL을 생성할 수도 있습니다.
현재 AWS Toolkit for Visual Studio는 Mac용 Visual Studio를 지원하지 않습니다.
-
AWS Toolkit for Visual Studio 사용 설명서의 Installing and setting up the Toolkit for Visual Studio 지침에 따라 AWS Toolkit for Visual Studio를 설치합니다.
-
다음 단계, AWS Toolkit for Visual Studio 사용 설명서의 AWS에 연결 단계를 사용하여 AWS에 연결합니다.
-
AWS Explorer라는 레이블이 붙은 왼쪽 패널에서 객체를 업로드하려는 버킷을 마우스 오른쪽 버튼으로 클릭합니다.
-
미리 서명된 URL 생성...을 선택합니다.
-
팝업 창에서 미리 서명된 URL의 만료 날짜와 시간을 설정합니다.
-
객체 키의 경우 업로드할 파일의 이름을 설정합니다. 업로드하는 파일은 이 이름과 정확히 일치해야 합니다. 동일한 객체 키를 가진 객체가 버킷에 이미 존재하는 경우 Amazon S3는 기존 객체를 새로 업로드한 객체로 대체합니다.
-
PUT을 선택하여 이 미리 서명된 URL이 객체를 업로드하는 데 사용되도록 지정합니다.
-
생성 버튼을 선택합니다.
-
URL을 클립보드에 복사하려면 복사를 선택합니다.
-
이 URL을 사용하려면 curl
명령으로 PUT 요청을 전송합니다. 파일의 전체 경로와 미리 서명된 URL 자체를 포함하세요.
curl -X PUT -T "/path/to/file
" "presigned URL
"
제한된 시간 동안 S3 작업을 수행할 수 있는 미리 서명된 URL을 생성할 수 있습니다.
- Python
-
다음 Python 스크립트는 S3 범용 버킷에 객체를 업로드하기 위해 PUT
미리 서명된 URL을 생성합니다.
-
스크립트의 내용을 복사하여 ‘put-only-url.py
’ 파일로 저장합니다. 다음 예시를 사용하려면 user input placeholders
를 실제 정보(예: 파일 이름)로 바꾸세요.
import argparse
import boto3
from botocore.exceptions import ClientError
def generate_presigned_url(s3_client, client_method, method_parameters, expires_in):
"""
Generate a presigned Amazon S3 URL that can be used to perform an action.
:param s3_client: A Boto3 Amazon S3 client.
:param client_method: The name of the client method that the URL performs.
:param method_parameters: The parameters of the specified client method.
:param expires_in: The number of seconds the presigned URL is valid for.
:return: The presigned URL.
"""
try:
url = s3_client.generate_presigned_url(
ClientMethod=client_method,
Params=method_parameters,
ExpiresIn=expires_in
)
except ClientError:
print(f"Couldn't get a presigned URL for client method '{client_method}'.")
raise
return url
def main():
parser = argparse.ArgumentParser()
parser.add_argument("bucket", help="The name of the bucket.")
parser.add_argument(
"key", help="The key (path and filename) in the S3 bucket.",
)
args = parser.parse_args()
# By default, this will use credentials from ~/.aws/credentials
s3_client = boto3.client("s3")
# The presigned URL is specified to expire in 1000 seconds
url = generate_presigned_url(
s3_client,
"put_object",
{"Bucket": args.bucket, "Key": args.key},
1000
)
print(f"Generated PUT presigned URL: {url}")
if __name__ == "__main__":
main()
-
파일을 업로드하기 위해 PUT
미리 서명된 URL을 생성하려면 버킷 이름과 원하는 객체 경로로 다음 스크립트를 실행합니다.
다음 명령에서는 예제 값을 사용합니다. user input placeholders
를 사용자의 정보로 대체합니다.
python put-only-url.py
amzn-s3-demo-bucket
<object-path>
스크립트는 PUT
미리 서명된 URL을 출력합니다.
Generated PUT presigned URL: https://amzn-s3-demo-bucket
.s3.amazonaws.com/object.txt
?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE
&Signature=vjbyNxybdZaMmLa%2ByT372YEAiv4%3D
&Expires=1741978496
-
이제 다음 curl을 통해 생성된 미리 서명된 URL을 사용하여 파일을 업로드할 수 있습니다.
curl -X PUT -T "path/to/your/local/file"
"generated-presigned-url"
AWS SDK를 사용하여 객체를 업로드하기 위한 미리 서명된 URL을 생성하는 추가 예제는 Create a presigned URL for Amazon S3 by using an AWS SDK를 참조하세요.