aws: add example of getting value from Secrets Manager
This commit is contained in:
parent
4ca809b43e
commit
1139ff9761
2 changed files with 39 additions and 1 deletions
|
@ -35,4 +35,6 @@ Here is an example of a resource permission giving access to a Lambda:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See [Fetch from Secrets Manager](/DevOps/AWS/AWS_Lambda/Code_examples/Fetch_from_Secrets_Manager.md) for a code example of retrieving a value from Secrets Manager.
|
||||||
|
|
||||||
// TODO: Add link to code example
|
// TODO: Add link to code example
|
||||||
|
|
|
@ -1,3 +1,39 @@
|
||||||
// TODO: Add example code of retrieving a value from SecretsManager
|
---
|
||||||
|
categories:
|
||||||
|
- DevOps
|
||||||
|
tags: [AWS, backend]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Fetch from Secrets Manager
|
||||||
|
|
||||||
|
## TypeScript
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const getSecret = async (): Promise<SomeCredentials> => {
|
||||||
|
const secretsManager = new AWS.SecretsManager();
|
||||||
|
const response = await secretsManager
|
||||||
|
.getSecretValue({ SecretId: process.env.SECRET_ARN as string })
|
||||||
|
.promise();
|
||||||
|
const secretValues = JSON.parse(response.SecretString as string);
|
||||||
|
|
||||||
|
if (secretValues) {
|
||||||
|
return {
|
||||||
|
accessToken: secretValues.POCKET_ACCESS_TOKEN,
|
||||||
|
consumerKey: secretValues.POCKET_CONSUMER_KEY,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
throw new Error("Failed to return Pocket credentials");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
type SomeCredentials = {
|
||||||
|
accessToken: string;
|
||||||
|
consumerKey: string;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
// TODO: Add example of deferring to local env var
|
// TODO: Add example of deferring to local env var
|
||||||
|
|
||||||
|
## Python
|
||||||
|
|
||||||
|
// TODO: Add Python example
|
||||||
|
|
Loading…
Add table
Reference in a new issue