

# AWS CLI에서 파일의 파라미터 로드
<a name="cli-usage-parameters-file"></a>

어떤 파라미터는 파일 이름을 인수로 예상하며 AWS CLI가 데이터를 로드합니다. 다른 어떤 파라미터는 파라미터 값을 명령줄에 입력된 텍스트 또는 파일에서 읽은 텍스트로 지정할 수 있습니다. 파일이 필수인지 또는 선택 사항인지에 관계없이 AWS CLI에서 파일을 이해할 수 있도록 파일을 올바르게 인코딩해야 합니다. 파일의 인코딩은 읽는 시스템의 기본 로캘과 일치해야 합니다. Python `locale.getpreferredencoding()` 메서드를 사용하여 이를 확인할 수 있습니다.

이 방법은 단일 파라미터에 대한 파일을 로드하기 위한 것입니다. 단일 파일로 여러 파라미터를 로드하는 방법에 대한 자세한 내용은 [AWS CLI에서 AWS CLI 스켈레톤 및 입력 파일](cli-usage-skeleton.md) 섹션을 참조하세요.

**참고**  
기본적으로 Windows PowerShell은 텍스트를 UTF-16으로 출력하며, 이는 JSON 파일과 여러 Linux 시스템에서 사용하는 UTF-8 인코딩과 충돌합니다. `-Encoding ascii`에서 결과 파일을 읽을 수 있도록 PowerShell `Out-File` 명령과 함께 AWS CLI를 사용하는 것이 좋습니다.

**Topics**
+ [파일에서 파라미터를 로드하는 방법](#cli-usage-parameters-file-how)
+ [이진 파일](#cli-usage-parameters-file-binary)
+ [파일을 간편 구문 값으로 로드](#cli-usage-parameters-file-shorthand)

## 파일에서 파라미터를 로드하는 방법
<a name="cli-usage-parameters-file-how"></a>

모두 명령줄 파라미터 값으로 입력하려고 하는 것보다 파일에서 파라미터 값을 가져오는 것이 편리할 때가 있습니다(예: 파라미터가 복잡한 JSON 문자열일 때). 값을 포함하는 파일을 지정하려면 파일 URL을 다음 형식으로 지정합니다.

```
file://complete/path/to/file
```
+ 처음 두 개의 슬래시 '/' 문자는 사양의 일부입니다. 필수 경로가 '/'로 시작하면 결과는 슬래시 문자 세 개(`file:///folder/file`)입니다.
+ URL은 실제 파라미터 내용이 포함된 파일로의 경로를 제공합니다.
+ 공백이나 특수 문자가 있는 파일을 사용하는 경우 터미널의 [인용 및 이스케이프 규칙](cli-usage-parameters-quoting-strings.md)을 따릅니다.

다음 예제의 파일 경로는 현재 작업 디렉터리를 기준으로 해석됩니다.

------
#### [ Linux or macOS ]

```
// Read from a file in the current directory
$ aws ec2 describe-instances --filters file://filter.json

// Read from a file in /tmp
$ aws ec2 describe-instances --filters file:///tmp/filter.json

// Read from a file with a filename with whitespaces
$ aws ec2 describe-instances --filters 'file://filter content.json'
```

------
#### [ Windows command prompt ]

```
// Read from a file in C:\temp
C:\> aws ec2 describe-instances --filters file://C:\temp\filter.json

// Read from a file with a filename with whitespaces
C:\> aws ec2 describe-instances --filters "file://C:\temp\filter content.json"
```

------

`file://` 접두사 옵션은 "`~/`", "`./`", "`../`"를 포함한 Unix 스타일의 확장을 지원합니다. Windows에서는 "`~/`" 표현식이 `%USERPROFILE%` 환경 변수에 저장된 사용자 디렉터리로 확장합니다. 예를 들어, Windows 10은 일반적으로 `%USERPROFILE%` 아래에 사용자 디렉터리가 있습니다.

다른 JSON 문서 값으로 포함되는 JSON 문서는 계속 이스케이프해야 합니다.

```
$ aws sqs create-queue --queue-name my-queue --attributes file://attributes.json
```

**attributes.json**

```
{
  "RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-west-2:0123456789012:deadletter\", \"maxReceiveCount\":\"5\"}"
}
```

## 이진 파일
<a name="cli-usage-parameters-file-binary"></a>

이진 데이터를 파라미터로 갖고 있는 명령의 경우 `fileb://` 접두사를 사용하여 데이터가 이진 콘텐츠임을 지정합니다. 이진 데이터를 수락하는 명령은 다음과 같습니다.
+  **`aws ec2 run-instances:`** `--user-data` 파라미터.
+  **`aws s3api put-object:`** `--sse-customer-key` 파라미터.
+  **`aws kms decrypt:`** `--ciphertext-blob` 파라미터.

다음 예제에서는 Linux 명령줄 도구를 사용하여 이진 256비트 AES 키를 생성한 다음, 이를 Amazon S3에 제공하여 업로드된 파일 서버측을 암호화합니다.

```
$ dd if=/dev/urandom bs=1 count=32 > sse.key
32+0 records in
32+0 records out
32 bytes (32 B) copied, 0.000164441 s, 195 kB/s
$ aws s3api put-object \
    --bucket amzn-s3-demo-bucket \
    --key test.txt \
    --body test.txt \
    --sse-customer-key fileb://sse.key \
    --sse-customer-algorithm AES256
{
    "SSECustomerKeyMD5": "iVg8oWa8sy714+FjtesrJg==",
    "SSECustomerAlgorithm": "AES256",
    "ETag": "\"a6118e84b76cf98bf04bbe14b6045c6c\""
}
```

JSON 형식의 파라미터를 포함하는 파일을 참조하는 다른 예제는 [사용자에게 IAM 관리형 정책 연결](cli-services-iam.md#cli-services-iam-policy) 섹션을 참조하세요.

## 파일을 간편 구문 값으로 로드
<a name="cli-usage-parameters-file-shorthand"></a>

값이 크거나 복잡한 간편 구문을 사용하는 경우 파일에 값으로 로드하는 것이 더 쉬운 경우가 많습니다. 파일을 간편 구문 값으로 로드하려면 형식이 약간 변경됩니다. `key=value` 대신 `=` 연산자 대신 `@=` 연산자를 사용합니다. `@=`는 AWS CLI에 값을 문자열이 아닌 파일 경로로 읽어야 함을 보여줍니다. 다음 예제에서는 해당 값에 대한 파일을 로드하는 키-값 페어를 보여줍니다.

------
#### [ Linux or macOS ]

```
--option key@=file://template.txt
```

------
#### [ Windows ]

```
--option "key1@=file://template.txt"
```

------

다음 예제에서는 `aws rolesanywhere create-trust-anchor` 명령에 대한 인증서 파일을 로드하는 방법을 보여줍니다.

```
$ aws rolesanywhere create-trust-anchor --name TrustAnchor \
    --source sourceData={x509CertificateData@=file://root-ca.crt},sourceType="CERTIFICATE_BUNDLE"  \ 
    --enabled
```

간편 구문에 대한 자세한 내용은 [AWS CLI에서 간편 구문 사용](cli-usage-shorthand.md) 섹션을 참조하세요.