

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

# 시간 기반 정책
<a name="example-policies-time-based"></a>

이 섹션의 정책은 프로모션 기간, 업무 시간 또는 둘의 조합 등 **월클록 시간**에서 결정됩니다. 서비스에서 모든 요청에 `context.system.now`대해 제공하는를 읽습니다.

시간 기반 조건은 일반적인 Cedar `when` 절이므로 이러한 페이지의 다른 모든 항목과 함께 구성됩니다. 보안 주체 검사, 입력 조건, 가드레일 또는 시간 조건은 모두 동일한 정책에 속할 수 있습니다.

작성 가이드의 나머지 부분과 마찬가지로 이러한 예제는 [예제의 리소스 구성](example-policies-reference.md)에 설명된 참조 게이트웨이에 대해 작성되므로 한 정책 엔진의 다른 예제와 결합할 수 있습니다.

**참고**  
시간 기반은 **시간** 기반과 동일하지 않습니다. 시간 기반 조건은 현재 시간을 묻고, 시간 조건은이 세션에서 이미 발생한 일을 묻습니다. 자세한 내용은 [임시 정책 예제](example-policies-temporal.md)를 참조하세요.

## 작동 방식
<a name="example-policies-time-based-how"></a>

정책 평가 중에 현재 UTC 타임스탬프는 평가 컨텍스트의 일부로 제공됩니다.

```
// Current datetime in UTC
context.system.now
```

Cedar의 날짜/시간 함수를 사용하여 시간 기반 조건을 생성할 수 있습니다.
+  `datetime("YYYY-MM-DDTHH:MM:SSZ")` - 날짜/시간 값 생성
+  `duration("Xh")` - 기간 생성(시간, 분, 초)
+  `.toTime()` - 날짜/시간에서 하루 중 시간 추출
+ 비교 연산자: `<` , `⇐` , `>` , `>=` , `==` 

## 절대 날짜 및 시간 범위 제한
<a name="example-policies-time-absolute"></a>

특정 일정 기간 내에 정책을 적용합니다.

### 예: 등록 기간 열기
<a name="example-policies-time-absolute-example"></a>

```
permit (
  principal,
  action == AgentCore::Action::"InsuranceAPI___calculate_premium",
  resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/insurance-gw-a1b2c3d4e5"
)
when {
  context.system.now >= datetime("2025-01-01T00:00:00Z") &&
  context.system.now < datetime("2025-02-01T00:00:00Z")
};
```

 **사용 사례:** 2025년 1월 공개 등록 기간 동안에만 프리미엄을 인용합니다.

## 일일 반복 시간 제한
<a name="example-policies-time-daily"></a>

매일 반복되는 시간대를 기준으로 정책을 적용합니다.

### 예: 업무 시간 정책
<a name="example-policies-time-daily-example"></a>

```
permit (
  principal,
  action == AgentCore::Action::"InsuranceAPI___disburse_payment",
  resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/insurance-gw-a1b2c3d4e5"
)
when {
  duration("9h") <= context.system.now.toTime() &&
  context.system.now.toTime() <= duration("17h")
};
```

 **사용 사례:** 업무 시간(매일 오전 9시\~오후 5시 UTC)에만 지불합니다.

## 통합 날짜 및 시간 제한
<a name="example-policies-time-combined"></a>

절대 날짜와 일일 시간 제한을 결합합니다.

### 예: 일일 시간이 포함된 등록 기간
<a name="example-policies-time-combined-example"></a>

```
permit (
  principal,
  action == AgentCore::Action::"InsuranceAPI___update_coverage",
  resource == AgentCore::Gateway::"arn:aws:bedrock-agentcore:us-west-2:123456789012:gateway/insurance-gw-a1b2c3d4e5"
)
when {
  // Valid dates: February 2025
  context.system.now >= datetime("2025-02-01T00:00:00Z") &&
  context.system.now < datetime("2025-03-01T00:00:00Z") &&
  // Valid hours: 9am-9pm UTC daily
  duration("9h") <= context.system.now.toTime() &&
  context.system.now.toTime() <= duration("21h")
};
```

 **사용 사례:** 매일 오전 9시에서 오후 9시 사이에 2025년 2월 중에만 적용 범위 변경을 허용합니다.

## 시간대 처리
<a name="example-policies-time-timezone"></a>

모든 날짜/시간 값은 UTC여야 합니다. 정책 엔진은 시간대 변환 또는 시간대 인식 정책을 지원하지 않습니다.

정책에서 시간을 지정할 때는 항상 UTC를 사용합니다. 비즈니스가 다른 시간대에서 운영되는 경우 정책을 생성하기 전에 현지 시간을 UTC로 변환합니다.