Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
IT Security DownloadsGitHub Release: microsoft/WSL v3.0.0 (25.09.2026)(25.09.2026 um 02:04 Uhr)
•••••••
YouTube Security VideosTechLinked: Apple says no more upgradeability(25.09.2026 um 01:02 Uhr)
•
Podcasts & Audio BriefingsiPhone 18, iPhone Duo und AirPods auf dem Prüfstand | CHIP.Chat #44(25.09.2026 um 00:00 Uhr)
•
YouTube Security VideosGoogle Cloud Tech: A Developer’s Guide to Gemini 3.5 Transcribe(25.09.2026 um 01:00 Uhr)
•
IT Security DownloadsGitHub Release: microsoft/WSL v3.0.0 (25.09.2026)(25.09.2026 um 02:04 Uhr)
•••••••
YouTube Security VideosTechLinked: Apple says no more upgradeability(25.09.2026 um 01:02 Uhr)
•
Podcasts & Audio BriefingsiPhone 18, iPhone Duo und AirPods auf dem Prüfstand | CHIP.Chat #44(25.09.2026 um 00:00 Uhr)
•
YouTube Security VideosGoogle Cloud Tech: A Developer’s Guide to Gemini 3.5 Transcribe(25.09.2026 um 01:00 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

AWS Secrets Manager: How to Set Up Secrets and Fetch Them in a Python Lambda

Managing sensitive information such as database passwords, API keys, and tokens is a critical part of building secure cloud applications. Hardcoding secrets in source code or configuration files is a common anti-pattern that leads to…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Managing sensitive information such as database passwords, API keys, and tokens is a critical part of building secure cloud applications. Hardcoding secrets in source code or configuration files is a common anti-pattern that leads to security vulnerabilities.



AWS Secrets Manager provides a secure, scalable, and auditable way to store and retrieve secrets dynamically at runtime. In this blog, we will cover:




  1. What AWS Secrets Manager is

  2. How to create and store secrets

  3. IAM permissions required

  4. How to fetch secrets in a Python AWS Lambda

  5. Best practices






1. What Is AWS Secrets Manager?



AWS Secrets Manager is a managed service that helps you:




  • Securely store secrets (credentials, API keys, tokens)

  • Encrypt secrets using AWS KMS

  • Control access via IAM

  • Rotate secrets automatically (for supported services)

  • Retrieve secrets programmatically at runtime



Typical use cases:




  • Database credentials (RDS, Aurora)

  • Third-party API keys

  • JWT signing secrets

  • OAuth client secrets






2. Creating a Secret in AWS Secrets Manager



Step 1: Open AWS Secrets Manager



Log in to the AWS Console



Navigate to Secrets Manager



Click Store a new secret



Step 2: Choose Secret Type



Select Other type of secret if you want to store custom values such as API keys.



Example (Key/Value pairs):

DB_USERNAME = admin

DB_PASSWORD = StrongPassword@123

DB_HOST = mydb.cluster-xyz.us-east-1.rds.amazonaws.com



Secrets Manager stores these values as encrypted JSON.





Step 3: Configure Encryption




  • Choose the default AWS-managed KMS key



or




  • Select a customer-managed KMS key for stricter compliance





Step 4: Name the Secret



Give the secret a clear, environment-aware name:



myapp/dev/database

myapp/staging/database

myapp/prod/database



This naming strategy avoids accidental cross-environment access.





Step 5: Review and Create



Click Store. Your secret is now securely stored.





3. IAM Permissions for Lambda



Your Lambda function must have permission to read secrets.



IAM Policy Example



Attach this policy to the Lambda execution role:




{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:myapp/dev/database*"
}
]
}






Important:

Always scope the Resource to specific secrets instead of using "*".





4. Fetching Secrets in a Python Lambda





Step 1: Python Dependencies



AWS Lambda already includes:




  • boto3

  • botocore



No additional libraries are required.





Step 2: Python Code to Fetch Secrets





import json
import boto3
from botocore.exceptions import ClientError

def get_secret(secret_name, region_name="us-east-1"):
client = boto3.client(
service_name="secretsmanager",
region_name=region_name
)

try:
response = client.get_secret_value(SecretId=secret_name)
except ClientError as e:
raise RuntimeError(f"Unable to retrieve secret: {e}")

# Secrets are usually stored as JSON strings
if "SecretString" in response:
return json.loads(response["SecretString"])
else:
# Binary secrets (rare case)
return response["SecretBinary"]







Step 3: Using Secrets in Lambda Handler





def lambda_handler(event, context):
secret_name = "myapp/dev/database"

secrets = get_secret(secret_name)

db_user = secrets["DB_USERNAME"]
db_password = secrets["DB_PASSWORD"]
db_host = secrets["DB_HOST"]

# Example usage
print(f"Connecting to DB at {db_host} with user {db_user}")

return {
"statusCode": 200,
"body": "Secrets fetched successfully"
}







5. Performance Consideration (Important)



Each call to GetSecretValue is a network call.



Recommended Optimization: Cache Secrets



Because Lambda execution environments are reused, you can cache secrets at module level:




_cached_secrets = None

def get_cached_secret(secret_name):
global _cached_secrets
if _cached_secrets is None:
_cached_secrets = get_secret(secret_name)
return _cached_secrets






This reduces latency and API calls significantly.






6. Environment-Based Secret Management



Use environment variables to control which secret is loaded:



SECRET_NAME = myapp/dev/database




import os

secret_name = os.environ["SECRET_NAME"]
secrets = get_cached_secret(secret_name)






This enables:




  • Same codebase across DEV / STAGE / PROD

  • Environment-specific secrets

  • Safer deployments






7. Security and Best Practices




  • Never hardcode secrets

  • Use least-privilege IAM policies

  • Use separate secrets per environment

  • Enable automatic rotation where supported

  • Cache secrets inside Lambda for performance

  • Log carefully—never log secret values

  • Prefer Secrets Manager over SSM Parameter Store for highly sensitive data

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - AWS Secrets Manager: How to Set Up Secrets and Fetch Them in a Python Lambda
id: 91298eb4-235f-4db8-8d3e-55c2a23b580d
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "AWS Secrets Manager: How to Se" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("AWS Secrets Manager How to Set Up Secret")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*AWS Secrets Manager How to Set Up Secret*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "AWS Secrets Manager How to Set Up Secret"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich AWS Secrets Manager: How to Set Up Secre.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten AWS Secrets Manager: How to Set Up Secrets and Fetch Them in a Python Lambda

Thematisch verwandte Begriffe: Secrets, Manager, Fetch, Them · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-87722 | Uncontrolled Resource Consumption (CWE-400 / CWE-1333) in regex search q…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle