Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions awscli/customizations/cloudfront.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import sys
import time
import random
import uuid

import rsa
from botocore.utils import parse_to_aware_datetime
Expand Down Expand Up @@ -63,7 +62,7 @@ def register(event_handler):


def unique_string(prefix='cli'):
return '%s-%s-%s' % (prefix, int(time.time()), random.randint(1, 1000000))
return '%s-%s' % (prefix, uuid.uuid4())


def _add_paths(argument_table, **kwargs):
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/customizations/test_cloudfront.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import re

from awscli.testutils import unittest
from awscli.customizations.cloudfront import unique_string


class TestUniqueString(unittest.TestCase):

UUID_RE = re.compile(
r'^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
)

def test_default_prefix(self):
result = unique_string()
self.assertTrue(result.startswith('cli-'), result)

def test_custom_prefix(self):
result = unique_string(prefix='myprefix')
self.assertTrue(result.startswith('myprefix-'), result)

def test_suffix_is_uuid4(self):
result = unique_string()
suffix = result[len('cli-'):]
self.assertRegex(suffix, self.UUID_RE)

def test_values_are_unique(self):
results = {unique_string() for _ in range(1000)}
self.assertEqual(len(results), 1000)