

버전 4(V4) AWS SDK for .NET 가 릴리스되었습니다.

변경 사항 해제 및 애플리케이션 마이그레이션에 대한 자세한 내용은 [마이그레이션 주제를](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html) 참조하세요.

 [https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/net-dg-v4.html)

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 를 사용하는 간단한 Windows 기반 애플리케이션 AWS SDK for .NET
<a name="quick-start-s3-1-winvs"></a>

이 자습서에서는 Windows AWS SDK for .NET 에서 Visual Studio 및 .NET Core와 함께를 사용합니다. 이 자습서는 SDK를 사용하여 소유한 [Amazon S3 버킷](https://docs.aws.amazon.com/AmazonS3/latest/userguide/)을 나열하고 선택적으로 버킷을 생성하는 방법을 보여줍니다.

Visual Studio 및 .NET Core를 사용하여 Windows에서 이 자습서를 수행하게 됩니다. 개발 환경을 구성하는 다른 방법은 [용 도구 체인 설치 및 구성 AWS SDK for .NET](net-dg-dev-env.md)을 참조하십시오.

**Visual Studio 및 .NET Core를 통한 Windows 개발에 필요한 항목:**
+ [Microsoft Visual Studio](https://visualstudio.microsoft.com/vs/)
+ Microsoft .NET Core 2.1, 3.1 이상

  일반적으로 Visual Studio의 최신 버전을 설치할 때 기본적으로 포함됩니다.

**참고**  
이 자습서를 사용하기 전에 먼저 [도구 체인을 설치](net-dg-dev-env.md)하고 [SDK 인증을 구성](creds-idc.md)해야 합니다.

## 단계
<a name="s3-1-winvs-steps"></a>
+ [프로젝트 생성](#s3-1-winvs-create-project)
+ [코드 생성](#s3-1-winvs-code)
+ [애플리케이션을 실행합니다](#s3-1-winvs-run)
+ [정리](#s3-1-winvs-clean-up)

## 프로젝트 생성
<a name="s3-1-winvs-create-project"></a>

1. Visual Studio를 열고 **콘솔 앱** 템플릿의 C\$1 버전을 사용하는 새 프로젝트를 생성합니다. 즉, "....NET에서 실행할 수 있는 명령줄 애플리케이션 생성의 경우..."라는 설명이 있습니다. `S3CreateAndList` 프로젝트의 이름을 지정합니다.
**참고**  
콘솔 앱 템플릿의 .NET Framework 버전을 선택하지 마십시오. 선택했다면 .NET Framework 4.7.2 이상을 사용해야 합니다.

1. 새로 생성된 프로젝트를 로드한 상태에서 **도구**, **NuGet Package Manager(NuGet 패키지 관리자)**, **Manage NuGet Packages for Solution(솔루션을 위한 NuGet 패키지 관리)**을 선택합니다.

1. `AWSSDK.S3`, `AWSSDK.SecurityToken`, `AWSSDK.SSO` 및 `AWSSDK.SSOOIDC`의 NuGet 패키지를 찾아 프로젝트에 설치합니다.

   이 프로세스는 [NuGet 패키지 관리자](https://www.nuget.org/profiles/awsdotnet)에서 NuGet 패키지를 설치합니다. 이 자습서에 필요한 NuGet 패키지를 정확하게 알고 있으므로 이제 이 단계를 수행할 수 있습니다. 또한 필요한 패키지가 개발 중에 알려지게 되는 것이 일반적입니다. 이 경우 유사한 프로세스를 따라 설치하십시오.

1. 명령 프롬프트에서 애플리케이션을 실행하려는 경우 이제 명령 프롬프트를 열고 빌드 출력이 포함될 폴더로 이동합니다. 일반적으로 `S3CreateAndList\S3CreateAndList\bin\Debug\net6.0`과 비슷하지만, 환경에 따라 달라집니다.

## 코드 생성
<a name="s3-1-winvs-code"></a>

1. `S3CreateAndList` 프로젝트에서 `Program.cs`를 찾아 IDE에서 엽니다.

1. 내용을 다음 코드로 바꾸고 파일을 저장합니다.

   ```
   using System;
   using System.Threading.Tasks;
   
   // NuGet packages: AWSSDK.S3, AWSSDK.SecurityToken, AWSSDK.SSO, AWSSDK.SSOOIDC
   using Amazon.Runtime;
   using Amazon.Runtime.CredentialManagement;
   using Amazon.S3;
   using Amazon.S3.Model;
   using Amazon.SecurityToken;
   using Amazon.SecurityToken.Model;
   
   namespace S3CreateAndList
   {
       class Program
       {
           // This code is part of the quick tour in the developer guide.
           // See https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/quick-start.html
           // for complete steps.
           // Requirements:
           // - An SSO profile in the SSO user's shared config file with sufficient privileges for
   		//   STS and S3 buckets.
           // - An active SSO Token.
           //    If an active SSO token isn't available, the SSO user should do the following:
           //    In a terminal, the SSO user must call "aws sso login".
   
           // Class members.
           static async Task Main(string[] args)
           {
               // Get SSO credentials from the information in the shared config file.
               // For this tutorial, the information is in the [default] profile.
               var ssoCreds = LoadSsoCredentials("default");
   
               // Display the caller's identity.
               var ssoProfileClient = new AmazonSecurityTokenServiceClient(ssoCreds);
               Console.WriteLine($"\nSSO Profile:\n {await ssoProfileClient.GetCallerIdentityArn()}");
   
               // Create the S3 client is by using the SSO credentials obtained earlier.
               var s3Client = new AmazonS3Client(ssoCreds);
   
               // Parse the command line arguments for the bucket name.
               if (GetBucketName(args, out String bucketName))
               {
                   // If a bucket name was supplied, create the bucket.
                   // Call the API method directly
                   try
                   {
                       Console.WriteLine($"\nCreating bucket {bucketName}...");
                       var createResponse = await s3Client.PutBucketAsync(bucketName);
                       Console.WriteLine($"Result: {createResponse.HttpStatusCode.ToString()}");
                   }
                   catch (Exception e)
                   {
                       Console.WriteLine("Caught exception when creating a bucket:");
                       Console.WriteLine(e.Message);
                   }
               }
   
               // Display a list of the account's S3 buckets.
               Console.WriteLine("\nGetting a list of your buckets...");
               var listResponse = await s3Client.ListBucketsAsync();
               Console.WriteLine($"Number of buckets: {listResponse.Buckets.Count}");
               foreach (S3Bucket b in listResponse.Buckets)
               {
                   Console.WriteLine(b.BucketName);
               }
               Console.WriteLine();
           }
   
           // 
           // Method to parse the command line.
           private static Boolean GetBucketName(string[] args, out String bucketName)
           {
               Boolean retval = false;
               bucketName = String.Empty;
               if (args.Length == 0)
               {
                   Console.WriteLine("\nNo arguments specified. Will simply list your Amazon S3 buckets." +
                     "\nIf you wish to create a bucket, supply a valid, globally unique bucket name.");
                   bucketName = String.Empty;
                   retval = false;
               }
               else if (args.Length == 1)
               {
                   bucketName = args[0];
                   retval = true;
               }
               else
               {
                   Console.WriteLine("\nToo many arguments specified." +
                     "\n\ndotnet_tutorials - A utility to list your Amazon S3 buckets and optionally create a new one." +
                     "\n\nUsage: S3CreateAndList [bucket_name]" +
                     "\n - bucket_name: A valid, globally unique bucket name." +
                     "\n - If bucket_name isn't supplied, this utility simply lists your buckets.");
                   Environment.Exit(1);
               }
               return retval;
           }
   
           //
           // Method to get SSO credentials from the information in the shared config file.
           static AWSCredentials LoadSsoCredentials(string profile)
           {
               var chain = new CredentialProfileStoreChain();
               if (!chain.TryGetAWSCredentials(profile, out var credentials))
                   throw new Exception($"Failed to find the {profile} profile");
               return credentials;
           }
       }
   
       // Class to read the caller's identity.
       public static class Extensions
       {
           public static async Task<string> GetCallerIdentityArn(this IAmazonSecurityTokenService stsClient)
           {
               var response = await stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest());
               return response.Arn;
           }
       }
   }
   ```

1. 애플리케이션을 빌드합니다.
**참고**  
이전 버전의 Visual Studio를 사용하는 경우 다음과 유사한 빌드 오류가 발생할 수 있습니다.  
“C\$1 7.0에서는 '비동기 메인' 기능을 사용할 수 없습니다. 언어 버전 7.1 이상을 사용하십시오.”  
이 오류가 발생하면 해당 언어의 최신 버전을 사용하도록 프로젝트를 설정하세요. 이 작업은 일반적으로 프로젝트 속성, **빌드**, **고급**에서 수행됩니다.

## 애플리케이션을 실행합니다
<a name="s3-1-winvs-run"></a>

1. 명령줄 인수 없이 애플리케이션을 실행합니다. 명령 프롬프트(이전에 연 경우) 또는 IDE에서 이 작업을 수행합니다.

1. 출력을 검사하여 소유한 Amazon S3 버킷 수(있는 경우)와 해당 이름을 확인합니다.

1. 새 Amazon S3 버킷의 이름을 선택합니다. "dotnet-quicktour-s3-1-winvs-"를 기본으로 사용하고 GUID 또는 사용자 이름과 같은 고유한 항목을 추가합니다. [Amazon S3 사용 설명서](https://docs.aws.amazon.com/AmazonS3/latest/userguide/)의 [버킷 이름 지정 규칙](https://docs.aws.amazon.com/AmazonS3/latest/userguide/BucketRestrictions.html#bucketnamingrules)에 설명된 대로 버킷 이름 규칙을 준수해야 합니다.

1. 애플리케이션을 다시 실행합니다. 이번에는 버킷 이름을 제공합니다.

   명령줄에서 다음 명령의 *amzn-s3-demo-bucket*을 선택한 버킷의 이름으로 바꿉니다.

   ```
   S3CreateAndList amzn-s3-demo-bucket
   ```

   또는 IDE에서 애플리케이션을 실행하는 경우 **프로젝트**, **S3CreateAndList Properties(S3CreateAndList 속성)**, **디버깅**으로 선택하고 버킷 이름을 입력합니다.

1. 출력을 검사하여 생성된 새 버킷을 확인합니다.

## 정리
<a name="s3-1-winvs-clean-up"></a>

이 자습서를 수행하는 동안 현재 정리하도록 선택할 수 있는 몇 가지 리소스를 만들었습니다.
+ 이전 단계에서 애플리케이션이 생성한 버킷을 유지하지 않으려면 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)에서 Amazon S3 콘솔을 사용하여 삭제합니다.
+ .NET 프로젝트를 유지하지 않으려면 개발 환경에서 `S3CreateAndList` 폴더를 제거하십시오.

## 다음으로 진행할 단계
<a name="s3-1-winvs-next"></a>

[간략한 설명 메뉴](quick-start.md)로 이동하거나 이 [간략한 설명의 끝](quick-start-next-steps.md)으로 바로 이동합니다.