AWS Access Key ID in PY
Match AWS access key IDs (both long-term AKIA and temporary ASIA prefixes).
Try it in the PY tester →Pattern
regexPY
\b(?:AKIA|ASIA)[0-9A-Z]{16}\b (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"\b(?:AKIA|ASIA)[0-9A-Z]{16}\b")
input_text = "AKIAIOSFODNN7EXAMPLE"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
Starts with AKIA (long-term user key) or ASIA (short-term STS session key), followed by exactly 16 uppercase alphanumeric characters. Word boundaries prevent partial matches.
Examples
Input
AKIAIOSFODNN7EXAMPLEMatches
AKIAIOSFODNN7EXAMPLE
Input
ASIAIOSFODNN7EXAMPLEMatches
ASIAIOSFODNN7EXAMPLE
Input
not a keyNo match
—