

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

# 보관된 메시지 정책 예
<a name="retained-message-policy-examples"></a>

[보관된 메시지](mqtt.md#mqtt-retain)를 사용하려면 특정 정책이 필요합니다. 보관된 메시지는 RETAIN 플래그가 설정되고에 의해 저장된 MQTT 메시지입니다 AWS IoT Core. 이 섹션에서는 보관된 메시지의 일반적인 사용을 허용하는 정책의 예를 보여줍니다.

**Topics**
+ [보관된 메시지를 연결하고 게시하는 정책](#retained-message-policy-examples-publish)
+ [보관된 Will 메시지를 연결하고 게시하는 정책](#retained-message-policy-examples-publish-lwt)
+ [보관된 메시지를 나열하고 가져오는 정책](#retained-message-policy-examples-list-get)

## 보관된 메시지를 연결하고 게시하는 정책
<a name="retained-message-policy-examples-publish"></a>

디바이스에서 보관된 메시지를 게시하려면 디바이스가 MQTT 보관된 메시지를 연결하고 게시할 수 있어야 합니다. 다음 정책은 주제에 대해 이러한 권한을 부여합니다(클라이언트 **device1**에 대한 `device/sample/configuration`). 연결 권한을 부여하는 다른 예는 [연결 및 게시 정책 예제](connect-and-pub.md) 섹션을 참조하세요.

****  

```
{
	"Version":"2012-10-17",		 	 	 
	"Statement": [
		{
			"Effect": "Allow",
			"Action": [
				"iot:Connect"
			],
			"Resource": [
				"arn:aws:iot:us-east-1:123456789012:client/device1"
			]
		},
		{
			"Effect": "Allow",
			"Action": [
				"iot:Publish",
				"iot:RetainPublish"
			],
			"Resource": [
				"arn:aws:iot:us-east-1:123456789012:topic/device/sample/configuration"
			]
		}
	]
}
```

## 보관된 Will 메시지를 연결하고 게시하는 정책
<a name="retained-message-policy-examples-publish-lwt"></a>

클라이언트는 클라이언트가 예기치 않게 연결 해제될 때 게시 AWS IoT Core 할 메시지를 구성할 수 있습니다. MQTT는 이러한 메시지를 [*Will* 메시지](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Will_Flag)라고 합니다. Will 메시지를 포함하려면 클라이언트의 연결 권한에 조건이 더 추가되어야 합니다.

다음 정책 문서는 AWS IoT Core 도 보관하는 `will`이라는 주제로 식별되는 Will 메시지를 연결하고 게시할 수 있는 권한을 모든 클라이언트에게 부여합니다.

****  

```
{
	"Version":"2012-10-17",		 	 	 
	"Statement": [
		{
			"Effect": "Allow",
			"Action": [
				"iot:Connect"
			],
			"Resource": [
				"arn:aws:iot:us-east-1:123456789012:client/device1"
			],
			"Condition": {
				"ForAllValues:StringEquals": {
					"iot:ConnectAttributes": [
						"LastWill"
					]
				}
			}
		},
		{
			"Effect": "Allow",
			"Action": [
				"iot:Publish",
				"iot:RetainPublish"
			],
			"Resource": [
				"arn:aws:iot:us-east-1:123456789012:topic/will"
			]
		}
	]
}
```

## 보관된 메시지를 나열하고 가져오는 정책
<a name="retained-message-policy-examples-list-get"></a>

서비스 및 애플리케이션은 [https://docs.aws.amazon.com//iot/latest/apireference/API_iotdata_ListRetainedMessages.html](https://docs.aws.amazon.com//iot/latest/apireference/API_iotdata_ListRetainedMessages.html) 및 [https://docs.aws.amazon.com//iot/latest/apireference/API_iotdata_GetRetainedMessage.html](https://docs.aws.amazon.com//iot/latest/apireference/API_iotdata_GetRetainedMessage.html)를 호출하여 MQTT 클라이언트를 지원할 필요 없이 보관된 메시지에 액세스할 수 있습니다. 이러한 작업을 호출하는 서비스 및 애플리케이션은 다음 예와 같은 정책을 사용하여 권한이 부여되어야 합니다.

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iot:ListRetainedMessages"
            ],
            "Resource": [
                "arn:aws:iot:us-east-1:123456789012:client/device1"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iot:GetRetainedMessage"
            ],
            "Resource": [
                "arn:aws:iot:us-east-1:123456789012:topic/foo"
            ]
        }
    ]
}
```