7 min readAWS → Microsoft Azure
Migrating Secrets Management: AWS Parameter Store vs Azure Key Vault
Learn how to replace AWS Parameter Store with Azure Key Vault, see side‑by‑side code, common pitfalls, and practical migration tips.
Why Secrets Management Is the First Thing You’ll Hit When Switching Clouds
When you move an application from Amazon Web Services to Microsoft Azure, the first thing that usually breaks isn’t the compute layer—it’s the way you keep passwords, API keys, and certificates safe. In AWS many teams rely on AWS Systems Manager Parameter Store (or the older AWS Secrets Manager) to fetch values at runtime. Azure’s counterpart is Azure Key Vault.
Both services provide encryption‑at‑rest, fine‑grained IAM, and versioning, but their SDKs, authentication flows, and naming conventions differ enough that a naïve copy‑paste will throw a ResourceNotFound or an authentication error. This post walks through a concrete, minimal example: reading a secret string from the store in a Node.js Lambda‑style function on AWS, then doing the same in an Azure Function written in JavaScript/TypeScript.
We’ll also list the exact “AWS‑to‑Azure” mapping you need to remember, and highlight the three most common traps that catch developers halfway through a migration.
The Task: Retrieve a Database Connection String at Runtime
Goal:
- In AWS: read the secret
prod/db/connectionStringfrom Parameter Store, using the default IAM role attached to the Lambda. - In Azure: read the secret
db-connection-stringfrom a Key Vault namedmy-prod-vault, using the managed identity of the Azure Function.
Both snippets assume the secret value is a plain string (no JSON).
AWS (Node.js, Lambda)
// file: getSecretAws.js
const { SSMClient, GetParameterCommand } = require("@aws-sdk/client-ssm");
// The Lambda execution role must have ssm:GetParameter permission
const ssm = new SSMClient({ region: "us-east-1" });
exports.handler = async (event) => {
try {
const command = new GetParameterCommand({
Name: "prod/db/connectionString",
WithDecryption: true,
});
const response = await ssm.send(command);
const connectionString = response.Parameter.Value;
console.log("✅ Got secret from Parameter Store");
// Use connectionString to connect to DB …
return { statusCode: 200, body: "OK" };
} catch (err) {
console.error("❌ Failed to fetch secret:", err);
return { statusCode: 500, body: "Error" };
}
};
Azure (JavaScript, Azure Functions)
// file: getSecretAzure/index.js
const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
// The Function App must have a System‑Assigned Managed Identity
// and that identity must be granted "get" on the secret.
const credential = new DefaultAzureCredential();
const vaultName = "my-prod-vault";
const url = `https://${vaultName}.vault.azure.net`;
const client = new SecretClient(url, credential);
module.exports = async function (context, req) {
try {
const secret = await client.getSecret("db-connection-string");
const connectionString = secret.value;
context.log("✅ Got secret from Azure Key Vault");
// Use connectionString to connect to DB …
context.res = { status: 200, body: "OK" };
} catch (err) {
context.log.error("❌ Failed to fetch secret:", err);
context.res = { status: 500, body: "Error" };
}
};
What Changed and Why
| Aspect | AWS (Parameter Store) | Azure (Key Vault) | Reason for Change |
|---|---|---|---|
| SDK package | @aws-sdk/client-ssm | @azure/keyvault-secrets + @azure/identity | Azure splits secret handling (Key Vault) from identity (Azure AD). |
| Authentication | Implicit IAM role attached to Lambda | DefaultAzureCredential which picks up the Function’s Managed Identity | Azure does not have an equivalent “instance profile”; you must enable a managed identity and grant it Key Vault Secrets User role. |
| Resource identifier | Simple hierarchical name (prod/db/connectionString) | Vault URL + secret name (db-connection-string) | Key Vault is a separate resource; the secret name lives inside the vault, not in a global namespace. |
| Decryption flag | WithDecryption: true | No flag – secrets are always returned decrypted (if you have access) | Parameter Store stores encrypted values; Key Vault stores them encrypted but returns plaintext after auth. |
| Error handling | ssm.send(command) throws ParameterNotFound | client.getSecret() throws RestError with 404 | Different exception types; map them in your error‑logging strategy. |
Concrete “AWS → Azure” Mappings
-
IAM Role → Managed Identity
- AWS: Attach an IAM role with
ssm:GetParameter. - Azure: Turn on System‑Assigned Managed Identity for the Function App, then assign the Key Vault Secrets User role on the vault (or a custom role with
secrets/get).
- AWS: Attach an IAM role with
-
Parameter Name → Secret Name
- AWS: Hierarchical strings (
/path/to/secret). - Azure: Flat names (
my-secret). If you need hierarchy, encode it in the name (myapp--db--connectionString).
- AWS: Hierarchical strings (
-
Region → Vault DNS
- AWS: Region is a client config (
region: "us-east-1"). - Azure: The vault’s DNS (
https://<vault>.vault.azure.net) already encodes the region; you only need the vault name.
- AWS: Region is a client config (
-
SDK Call
- AWS:
GetParameterCommand→ssm.send(). - Azure:
client.getSecret()→ returns aSecretBundle.
- AWS:
-
Permissions
- AWS: Policy JSON with
ssm:GetParameter. - Azure: Azure RBAC role assignment on the vault (or Access Policies if using the classic model).
- AWS: Policy JSON with
Three Pitfalls You’ll Hit (and How to Avoid Them)
1. Forgetting to Grant the Managed Identity Access
Symptom: AuthenticationFailed or 403 errors from Key Vault.
Fix:
- In the Azure portal, go to the Key Vault → Access control (IAM) → Add role assignment.
- Choose Key Vault Secrets User (or Contributor for broader access) and select the Function App’s managed identity.
- If you’re using the older Access policies tab, add a new policy for the identity with Get permission on secrets.
2. Mixing Up Secret Versions
AWS Parameter Store returns the latest version by default, but Azure Key Vault can return a specific version if you include it in the request URL.
Symptom: You think you’re getting the newest secret, but you’re actually pulling an older version because the client was instantiated with a versioned identifier.
Fix:
- Call
client.getSecret("secret-name")without a version argument to always get the latest. - If you need versioning, store the version string in an environment variable and pass it explicitly (
client.getSecret("secret-name", { version: "xxxx" })).
3. Assuming Secrets Are Plain Text
Both services can store binary data (e.g., certificates). In AWS you might have used String type; in Azure you might need Secret vs Certificate.
Symptom: The secret value appears as a base‑64 string or you get a SecretNotFound error.
Fix:
- Verify the secret’s content type in Azure Key Vault (
contentTypeproperty). - If you stored a PEM certificate, retrieve it as a secret and decode it in your code.
- For binary data, consider using Azure Key Vault Keys or Certificates instead of plain secrets.
Step‑by‑Step Migration Checklist
- Inventory all Parameter Store keys used by your code. Export them (
aws ssm describe-parameters). - Create an Azure Key Vault (or reuse an existing one) in the same region as your Function App.
- Migrate each secret:
# Example using Azure CLI az keyvault secret set --vault-name my-prod-vault \ --name db-connection-string \ --value "$(aws ssm get-parameter --name prod/db/connectionString --with-decryption --query Parameter.Value --output text)" - Enable Managed Identity on every Function App that needs a secret.
- Assign the Key Vault Secrets User role to the identity.
- Update code: replace
@aws-sdk/client-ssmwith Azure SDK imports, adjust names, and remove the decryption flag. - Test locally using
az login+az account setandDefaultAzureCredentialfallback to Azure CLI credentials. - Deploy and monitor logs for
403or404errors; fix IAM or naming mismatches.
Performance & Cost Considerations
- Latency: Both services are globally distributed, but Azure Key Vault adds an extra TLS handshake for each request. Cache the secret in memory (e.g., a static variable) if you need it on every request.
- Pricing: Parameter Store charges per API call after a free tier; Key Vault charges per operation and per secret version stored. For high‑throughput scenarios, consider Azure App Configuration with Key Vault references to reduce call volume.
TL;DR
- AWS: IAM role →
ssm.send(new GetParameterCommand(...))→ hierarchical name,WithDecryption. - Azure: Managed Identity →
new SecretClient(vaultUrl, new DefaultAzureCredential())→ flat secret name, no decryption flag. - Pitfalls: missing role assignment, version confusion, secret type mismatches.
By following the mappings and checklist above, you can replace Parameter Store with Key Vault without rewriting business logic, and you’ll avoid the three most common roadblocks that trip up developers during a cloud‑to‑cloud move.
FAQ
How do I test Azure Key Vault access locally?
Run az login and ensure the Azure CLI account has at least Key Vault Secrets User on the target vault. DefaultAzureCredential will then fall back to the CLI credential when you run the function locally.
Can I keep using AWS Parameter Store while I migrate?
Yes. You can run both SDKs side‑by‑side and gradually switch secrets. Just remember to keep IAM permissions in sync and avoid naming collisions.
What if I need to rotate a secret automatically?
Both services support rotation. In Azure, enable Secret rotation via an Azure Automation runbook or Azure Functions timer trigger that calls client.setSecret. In AWS, use Secrets Manager rotation Lambda. The code to fetch the secret stays the same; only the rotation mechanism differs.
#aws #azure #secrets #devops