Using HashiCorp Vault and AWS Lambda for Short-Lived Credentials
AWS Lambda functions are often granted more access than they need because static access keys are easy to distribute and difficult to manage safely. A stronger pattern is to let the function authenticate with its execution role, request temporary credentials from HashiCorp Vault, and use those credentials only for the duration of a task.
This approach suits event-driven systems that run across Australian AWS regions, from Sydney to Melbourne. It reduces the exposure created by long-lived secrets, while giving infrastructure teams central control over TTLs, policies, auditing, and emergency revocation.
| Approach | Credential lifetime | Operational effort | Suitable use |
|---|---|---|---|
| Static IAM access keys | Long-lived | Low initially, high during rotation | Legacy workloads only |
| AWS Secrets Manager keys | Usually long-lived | Moderate | Applications needing a simple managed store |
| Lambda execution role | Temporary AWS credentials | Low | Most AWS-native access |
| Vault AWS secrets engine | Short-lived, policy-controlled | Moderate to high | Hybrid, multi-account, and centralised secrets governance |
Why Short-Lived Credentials Fit Lambda
A Lambda execution environment may be reused, frozen, or replaced without warning. Credentials placed in deployment packages, environment variables, or temporary files can therefore remain available longer than intended. Short-lived AWS credentials reduce the useful lifetime of a leaked value and limit the blast radius of a compromised function.
Vault can generate credentials through its AWS secrets engine. Depending on the design, it can create an IAM user with a controlled lease or request temporary credentials through AWS Security Token Service. The STS-based model is generally preferable because it avoids creating and deleting IAM users for every invocation.
The lifetime should match the function’s real work. A five-minute function may need a credential lease of ten or fifteen minutes to allow for retries, while a long-running workflow may require renewal or a different orchestration pattern. A Vault token and the AWS credentials it produces have separate expiry controls, so both must be planned.
Choose Authentication And Credential Flow
The Lambda function should authenticate to Vault using the AWS authentication method rather than a hard-coded Vault token. Vault validates the function’s AWS identity, commonly through a signed sts:GetCallerIdentity request. The Vault role then maps that identity to policies and a defined token TTL.
A typical flow is:
- Lambda starts with an AWS execution role.
- The function signs an AWS identity request.
- Vault validates the request and issues a short-lived Vault token.
- The function reads from the AWS secrets engine.
- Vault returns temporary AWS credentials for an approved role.
- The function uses those credentials and discards them when the task ends.
The Vault role should bind to a specific IAM role ARN or tightly controlled account and identity attributes. Avoid broad account-wide bindings unless there is a strong reason. In multi-account environments, separate Vault roles and AWS roles make it easier to audit access between production, development, and shared services.
Build Vault And AWS Trust Boundaries
The AWS role assumed by Vault needs permission to generate the requested credentials. For an STS-based design, that may involve sts:AssumeRole against explicitly listed target roles. The target role’s trust policy must allow the Vault AWS account or broker role to assume it, and its permissions policy should contain only the actions required by the Lambda workload.
Vault policies should be equally narrow. A function that uploads objects to one S3 bucket does not need access to every path under the AWS secrets engine. Use separate secret paths, Vault roles, and AWS IAM roles for materially different workloads. This creates useful separation when a Sydney production function and a Melbourne test function have different data-handling requirements.
Vault itself becomes a critical security boundary. Protect the root token, use namespaces where appropriate, enable audit logging, and ensure unseal and recovery procedures are documented. Audit records should connect the Vault identity, AWS role, Lambda function, request path, and lease ID so an investigation can follow the complete credential chain.
Implement Lambda Retrieval Safely
The function should request credentials during initialisation or at the start of a handler, depending on its execution duration and concurrency profile. Caching a credential in memory can avoid an authentication request on every warm invocation, but the cache must check expiry and refresh before the lease becomes invalid. Never assume that a warm container will live for the full credential lifetime.
Keep Vault’s address and non-sensitive configuration in environment variables or deployment configuration. Do not place Vault tokens, AWS secret keys, or retrieved credentials in logs, error messages, Lambda responses, or tracing attributes. Mask exception output because SDK errors can sometimes include request parameters or response details.
For a private deployment, Lambda may use a VPC connection to reach Vault through internal DNS and routing. This commonly requires security groups, route tables, NAT or interface endpoints, and careful timeout settings. A function that cannot reach Vault should fail closed rather than falling back to a permanent key. If teams are comparing external implementation references, security reference material should supplement, rather than replace, the organisation’s own Vault and AWS threat model.
Manage Network Performance In Australian Regions
Network distance matters when Vault runs outside the AWS region where Lambda executes. A function in ap-southeast-2 calling a Vault cluster in the United States can spend a significant part of its timeout budget on authentication and credential retrieval. For Australian workloads, place Vault close to the principal execution region or provide a resilient regional access design.
Sydney and Melbourne are common choices for regulated or latency-sensitive workloads, while Perth-based teams may need to account for longer links to eastern Australian regions. Test using the same VPC, DNS path, security controls, and concurrency levels as production. A local “it works from my laptop” test says little about Lambda’s network path.
Vault availability must also match Lambda’s scaling behaviour. A sudden SQS backlog or API burst can create many simultaneous authentication requests. Use connection reuse where the runtime supports it, set sensible Lambda reserved concurrency, and monitor Vault request rates. Short-lived credentials are valuable, but an overloaded Vault cluster can still become a production dependency.
Operate, Test, And Rotate Reliably
Treat lease expiry and authentication failures as normal operational events rather than rare exceptions. Metrics should distinguish Vault connectivity failures, rejected AWS identities, denied secret paths, expired credentials, and downstream AWS authorisation errors. Alerts can then point to the right owner instead of producing a generic Lambda failure.
Australian organisations may also need evidence for controls aligned with the Essential Eight, APRA expectations, or customer security questionnaires. Vault audit logs, IAM CloudTrail events, Lambda logs, and deployment records should use consistent timestamps, preferably UTC with clear conversion for teams working AEST or AEDT.
Use the following operating practices:
- Set Vault token and AWS credential TTLs according to the function’s maximum execution time.
- Bind Vault authentication roles to exact Lambda execution role ARNs where practical.
- Restrict generated AWS permissions to named resources and required API actions.
- Test cold starts, warm invocations, retries, concurrency spikes, and Vault outages.
- Confirm that expired credentials are refreshed without requiring a new deployment.
- Alert on unusual lease volume, denied assumptions, and repeated authentication failures.
- Document break-glass access separately from the normal Lambda credential path.
With these controls, Lambda receives access when it needs it, for as long as it needs it, while Vault and AWS retain clear responsibility for identity, authorisation, auditing, and revocation.