Cloud Incident ResponseJuly 11, 2026 ·15 min read

The Complete Guide to Serverless Security: AWS Lambda, Azure Functions & GCP Cloud Run

Secure serverless apps across AWS, Azure, and GCP with IAM, secrets, APIs, logging, and CI/CD controls.

Oliver Bennett
Serverless security for AWS Lambda Azure Functions and GCP Cloud Run

What Are Serverless Security Best Practices and Why Do They Matter?

Serverless security best practices are the set of controls, configurations, and operational standards that protect cloud functions, such as AWS Lambda, Azure Functions, and Google Cloud Run, from unauthorized access, data exposure, injection attacks, and privilege abuse.

Unlike traditional server security, serverless architecture removes the operating system layer from your responsibility, but it does not remove the attack surface. It shifts it.

That distinction matters. Many engineering teams treat the removal of server management as a reduction in security responsibility. Regulators and attackers do not share that view.

According to the Cloud Security Alliance’s 2023 State of Cloud Security report, misconfiguration remains the leading cause of cloud security incidents, ahead of external attacks. In serverless environments specifically, the most common misconfigurations involve over-permissioned execution roles, exposed environment variables containing secrets, and functions triggered without authentication controls.

These are not exotic vulnerabilities. They are routine deployment errors that occur when teams build fast without a defined security framework.

Why Serverless Architecture Introduces a Different Kind of Risk

The appeal of serverless is straightforward: no servers to patch, auto-scaling by default, and pay-per-use pricing. AWS Lambda, Azure Functions, and Google Cloud Run have made it possible for small teams to ship production workloads at scale.

But the architecture that simplifies operations also changes how attacks succeed.

In a traditional application, a compromised server is a known failure point. In a serverless environment, the blast radius depends on what the function is permitted to do.

A Lambda function with an over-scoped IAM role does not just expose one endpoint. It can expose every AWS resource that role is authorized to access. The function itself may run for milliseconds. The damage it enables can persist indefinitely.

There is also the supply chain dimension. Serverless functions depend heavily on third-party packages. Security research has repeatedly shown that widely used open-source packages can carry known vulnerabilities, which makes dependency scanning essential for serverless workloads. When those packages end up in a deployed function, the function inherits the risk.

FaaS security risks are not theoretical. They are predictable consequences of deployment patterns that most teams have not yet formalized.

Serverless security framework for cloud functions

What Governing Bodies and Frameworks Say About Cloud Function Security

No single regulator governs serverless security in isolation, but several established frameworks apply directly.

The OWASP Serverless Top 10, developed specifically for function-as-a-service environments, identifies the most common attack categories, including injection via event data, insecure third-party dependencies, over-permissioned functions, and inadequate logging. It serves as the de facto reference point for security teams assessing serverless workloads.

For organizations operating under SOC 2, PCI DSS, or HIPAA, serverless functions that process, store, or transmit regulated data fall within scope for those frameworks.

The National Institute of Standards and Technology, NIST, Special Publication 800-204, “Security Strategies for Microservices-based Application Systems,” addresses serverless as part of a broader cloud-native security model and specifically calls out identity and access management, secrets management, and audit logging as baseline requirements.

The consequence of ignoring these standards is not abstract. A serverless function exposed to the internet without authentication, handling payment data, is a PCI DSS violation waiting to be discovered, either by an auditor or by an attacker.

AWS, Microsoft, and Google each publish their own security guidance for their respective platforms. AWS publishes the Lambda Security Best Practices documentation through the AWS Well-Architected Framework. Microsoft provides the Azure Functions security baseline, aligned to the Microsoft Cloud Security Benchmark. Google maintains security guidance for Cloud Run and Cloud Functions within its Cloud Architecture Framework.

These are not optional reading for teams running production workloads.

Understanding the frameworks is a necessary starting point. Knowing how to apply them consistently across three different cloud providers, while managing IAM policies, secrets, logging pipelines, and dependency scanning in each, is where most teams need structured support.

Our course, Serverless Security For AWS Lambda Azure Functions And GCP, gives cloud engineers and security practitioners the hands-on framework to implement these controls correctly across all three platforms, covering the real configurations that production environments require, not just the concepts.

Explore the Course → Serverless Security For AWS Lambda Azure Functions And GCP

How to Harden Serverless Security Across AWS Lambda, Azure Functions, and GCP Cloud Run

What Does Least Privilege Actually Look Like in a Serverless Environment?

The principle of least privilege is one of the most cited concepts in cloud security and one of the most inconsistently applied.

In serverless environments, it translates to a specific, non-negotiable requirement: every function must be assigned only the permissions it needs to complete its designated task, nothing broader and nothing inherited by default from a shared role.

In AWS Lambda, execution roles are assigned via IAM. The failure pattern seen most often in production environments is not a deliberate decision to over-permission a function. It is the absence of a deliberate decision at all.

A developer attaches an existing role because it works, and that role carries permissions accumulated across months of other projects. The function deploys successfully. The security gap opens quietly.

AWS provides a tool called IAM Access Analyzer that identifies unused permissions across roles. According to AWS documentation, teams using Access Analyzer as part of their deployment pipeline reduce over-permissioned role configurations significantly compared to those reviewing permissions manually on an ad hoc basis.

The tooling exists. The gap is in whether teams build it into standard practice.

Azure Functions addresses permissions through Managed Identities, a mechanism that allows a function to authenticate to other Azure services without storing credentials in code or configuration.

A system-assigned managed identity is scoped to a single function app and deleted when that app is removed. A user-assigned managed identity can be shared across resources but requires deliberate access control to avoid the same accumulation problem that affects AWS IAM roles.

Neither option is inherently safe. Both require intentional scoping.

On GCP, Cloud Run and Cloud Functions operate under service accounts. The default compute service account in GCP carries the Editor role, broad enough to read, write, and delete most resources in a project. Deploying a function under that default is the equivalent of giving every new hire a master key on their first day.

Google’s own security guidance explicitly recommends creating a dedicated service account for each function with only the permissions that function requires. That recommendation is documented. It is not consistently followed.

How Should Secrets Be Managed Across Three Cloud Platforms?

Hardcoded credentials in serverless functions are not a theoretical risk. The 2023 GitGuardian State of Secrets Sprawl report found over 10 million secrets exposed in public repositories that year, with cloud provider API keys among the most commonly leaked.

Serverless functions are a frequent source because developers working quickly under deployment pressure will sometimes use environment variables as a shortcut, and environment variables stored without encryption are readable by anyone with access to the function’s configuration.

Each major cloud provider offers a dedicated secrets management service:

  • AWS Secrets Manager allows Lambda functions to retrieve credentials at runtime via API call, with automatic rotation supported for common database engines.

  • Azure Key Vault provides equivalent functionality for Azure Functions, with access controlled through Managed Identity bindings rather than API keys.

  • GCP Secret Manager serves the same role for Cloud Run and Cloud Functions, with fine-grained IAM controls determining which service accounts can access which secrets.

The operational discipline required is consistent across all three platforms. Secrets must never be stored in environment variables without encryption. Rotation policies must be defined and enforced, not assumed.

Access to secrets management services must itself be logged and audited. A secret that rotates on schedule but whose access logs are never reviewed provides weaker protection than it appears to.

Serverless secrets management with secure cloud vaults

What Logging and Monitoring Controls Does Serverless Security Require?

One of the structural characteristics of serverless architecture is ephemeral execution. A Lambda function that runs for 300 milliseconds and terminates leaves no persistent process to monitor in the conventional sense.

This creates a gap in security observability that teams accustomed to server-based logging need to deliberately close.

AWS CloudTrail records API-level activity across Lambda invocations, IAM role assumptions, and Secrets Manager access. AWS CloudWatch captures function-level logs including execution duration, error rates, and custom log output.

Together, they provide the audit trail that compliance frameworks require, but only if logging is enabled, log groups are retained beyond the default period, and someone is actually reviewing anomalous patterns.

Azure Monitor and Azure Application Insights fulfill the equivalent function for Azure Functions. GCP Cloud Logging and Cloud Audit Logs serve that role for Cloud Run.

The architecture differs across providers, but the requirement is identical: every function invocation that touches sensitive data or performs a privileged action must produce a log entry, and that log must be retained and reviewable.

Threat detection in serverless environments also benefits from purpose-built tooling. AWS GuardDuty extended its coverage to Lambda in 2022, identifying anomalous invocation patterns and potential data exfiltration behaviors within function execution.

Azure Defender for Cloud and Google Security Command Center provide comparable monitoring capabilities for their respective platforms.

The logging infrastructure each provider offers is capable. The gap is almost never in the tooling. It is in whether teams configure it correctly from deployment, rather than retrofitting it after the first incident.

Serverless Security in Practice: APIs, Dependencies, and DevSecOps

How Do You Secure the API Layer in Front of Serverless Functions?

Serverless functions rarely operate in isolation. In most production architectures, they sit behind an API gateway, such as AWS API Gateway, Azure API Management, or Google Cloud Endpoints, that controls how external requests reach the function.

That gateway is not a security boundary by default. It becomes one only through deliberate configuration.

Authentication is the first control point. AWS API Gateway supports Lambda authorizers, which allow a custom function to validate tokens before the downstream function ever executes. It also supports native integration with Amazon Cognito for JWT and OAuth 2.0 validation.

Azure API Management provides OAuth 2.0 policy enforcement and subscription key validation at the gateway layer. GCP Cloud Endpoints supports API key validation and JWT verification through its service configuration.

All three mechanisms exist to ensure that unauthenticated requests are rejected before they consume function resources or touch application logic.

Rate limiting is the second control that teams consistently under-configure. A serverless function with no invocation throttle is exposed to both denial-of-service conditions and credential stuffing attacks that use function endpoints as validation targets.

AWS API Gateway allows usage plans and throttling limits to be set per API key and per stage. Azure API Management supports rate limiting through inbound processing policies. GCP Cloud Endpoints enforces quotas through service configuration.

The configuration takes minutes. The absence of it is a decision with consequences.

Web Application Firewall integration adds a third layer. AWS WAF can be attached directly to API Gateway or CloudFront distributions in front of Lambda. Azure WAF integrates with Azure Application Gateway and Azure Front Door. GCP Cloud Armor provides WAF capabilities for Cloud Run workloads via load balancer integration.

WAF rules can filter SQL injection attempts, cross-site scripting payloads, and request patterns consistent with known attack tooling before a single line of function code executes.

Serverless API security with gateway protection

Why Dependency Security Is a Serverless-Specific Problem

Every serverless function carries its dependencies into execution. Unlike a long-running server where a vulnerable package might exist without being invoked, a serverless function that imports a compromised library activates that vulnerability on every invocation.

The attack surface scales with deployment frequency.

The Log4Shell vulnerability, disclosed in December 2021, demonstrated this at scale. Functions using affected versions of the Log4j library were exposed the moment they were invoked, regardless of whether the development team was aware.

CISA issued an emergency directive requiring federal agencies to patch or mitigate within days. Organizations without automated dependency scanning had no systematic way to identify which functions were affected across their deployments.

Automated software composition analysis, using tools such as Snyk, OWASP Dependency-Check, or the native dependency scanning available in GitHub Advanced Security and AWS CodeGuru, should run at every build stage, not as a periodic audit.

A vulnerability introduced by a dependency update on a Tuesday afternoon should be caught before it reaches a staging environment, not after it reaches production.

Keeping function package sizes minimal also reduces the dependency surface. A function that imports only what it needs exposes fewer libraries to exploitation.

This is not a performance recommendation dressed as a security one. It is a direct reduction in the number of components that require monitoring and patching.

What Does DevSecOps Look Like for Serverless Workloads?

Shifting security left in a serverless CI/CD pipeline means treating security controls as deployment gates, not post-deployment reviews.

In practice, this requires:

  • Static analysis of function code and infrastructure-as-code templates before any deployment proceeds

  • Automated secret scanning to catch credentials committed to version control

  • Dependency vulnerability checks at build time

  • Infrastructure policy validation using tools such as AWS CloudFormation Guard, Azure Policy, or Open Policy Agent for GCP

Checkov and Terrascan are open-source tools that scan Terraform and CloudFormation templates for misconfigurations, including over-permissioned IAM roles, missing encryption settings, and functions deployed without VPC configuration where isolation is required.

Running these checks in a CI pipeline converts what would otherwise be a manual review into an automated gate that blocks non-compliant deployments before they reach any environment.

The cultural dimension matters as much as the tooling. Security controls that exist only in a separate review cycle, disconnected from the deployment workflow, will be bypassed under deadline pressure.

Controls embedded in the pipeline run every time, regardless of deadline.

If you are responsible for securing serverless workloads across AWS, Azure, or GCP, or preparing your team to do so, structured training is the most reliable way to move from awareness to applied capability.

Our course, Serverless Security For AWS Lambda Azure Functions And GCP walks practitioners through the real configurations, policy structures, and deployment controls that production environments require, built for engineers who need to implement these standards, not just understand them in principle.

Explore the Course → Serverless Security For AWS Lambda Azure Functions And GCP

Frequently Asked Questions

What Is the Biggest Security Risk in Serverless Architecture?

The most consistently documented risk in serverless architecture is over-permissioned execution roles. When a Lambda function, Azure Function, or Cloud Run service is granted broader IAM or RBAC permissions than its task requires, a successful exploit of that function can compromise resources far beyond the function itself.

The OWASP Serverless Top 10 identifies this as a primary attack vector. The risk is compounded in organizations where IAM roles are shared across functions or inherited from project-wide defaults without review.

Addressing it requires per-function role scoping and regular access analysis as part of the deployment process.

How Does Serverless Security Differ From Traditional Application Security?

Traditional application security assumes a persistent server where an operating system, network stack, and running processes can all be monitored and controlled.

Serverless removes that persistent layer. Functions execute ephemerally, sometimes for milliseconds, which means conventional endpoint security agents and network monitoring tools do not apply in the same way.

The attack surface shifts toward event inputs, IAM configurations, third-party dependencies, and secrets handling.

Security teams need to adapt their threat models accordingly, focusing on what the function is permitted to do and what data it processes, rather than where it runs.

Do Serverless Functions Need to Comply With PCI DSS and HIPAA?

Yes, if the function processes, stores, or transmits data that falls within scope for those frameworks, the function and its supporting infrastructure are subject to the same compliance requirements as any other system handling that data.

Current PCI DSS v4.x requirements apply to any component of the cardholder data environment regardless of the underlying compute model. HIPAA’s Security Rule applies to any electronic protected health information, including data processed by cloud functions.

Both frameworks require access controls, audit logging, encryption in transit and at rest, and documented security assessments, all of which have direct serverless equivalents.

What Is the OWASP Serverless Top 10?

The OWASP Serverless Top 10 is a reference document published by the Open Web Application Security Project that identifies the most critical security risks specific to function-as-a-service environments.

It covers event data injection, broken authentication, insecure serverless deployment configuration, over-permissioned function roles, inadequate logging and monitoring, insecure third-party dependencies, improper exception handling, and related vulnerabilities.

It is modeled on the OWASP Web Application Top 10 but adapted for the serverless execution model, where traditional controls such as firewalls and OS hardening do not apply directly.

Security teams use it as a structured checklist when assessing or designing serverless workloads.

How Do You Prevent Secret Exposure in Serverless Functions?

The primary control is to never store credentials, API keys, database passwords, or other secrets as plaintext environment variables in function configuration.

Each major cloud provider offers a dedicated secrets management service, such as AWS Secrets Manager, Azure Key Vault, and GCP Secret Manager, that allows functions to retrieve secrets at runtime through authenticated API calls, without the secrets ever appearing in deployment configuration or version control.

Access to those services should be controlled through IAM policies scoped to the specific function, with all access logged.

Secret rotation should be automated where the provider supports it, and application code should be scanned for hardcoded credentials as part of every CI/CD pipeline run.