-
Notifications
You must be signed in to change notification settings - Fork 156
feat(parameters): adds setParameter function to store SSM parameters #3020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
leandrodamascena
merged 12 commits into
aws-powertools:main
from
daschaa:feature/2871_put_parameter
Sep 11, 2024
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
16cd976
feat: adds implementation for setParameter
daschaa 1560335
chore: changes due to review
daschaa 6b0d7ee
Merge branch 'main' into feature/2871_put_parameter
daschaa 2822736
docs: adds documentation
daschaa de3ac4f
chore: adds end-to-end-tests
daschaa ffddb69
chore: changes name suffix of param
daschaa e0ebb21
chore: adds changes due to review
daschaa ed1f25f
Merge branch 'main' into feature/2871_put_parameter
dreamorosi 642dd1c
Update packages/parameters/src/ssm/setParameter.ts
dreamorosi 562ecb2
Update packages/parameters/src/ssm/setParameter.ts
dreamorosi 9d803d3
Update packages/parameters/tests/unit/setParameter.test.ts
dreamorosi 11cb54c
Apply suggestions from code review
dreamorosi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { setParameter } from '@aws-lambda-powertools/parameters/ssm'; | ||
|
||
export const handler = async (): Promise<void> => { | ||
// Store a string parameter | ||
const parameter = await setParameter('/my/parameter', { value: 'my-value' }); | ||
console.log(parameter); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { setParameter } from '@aws-lambda-powertools/parameters/ssm'; | ||
|
||
export const handler = async (): Promise<void> => { | ||
// Overwrite a string parameter | ||
const parameter = await setParameter('/my/parameter', { | ||
value: 'my-value', | ||
overwrite: true, | ||
}); | ||
console.log(parameter); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { SSMProvider } from './SSMProvider.js'; | ||
export { getParameter } from './getParameter.js'; | ||
export { setParameter } from './setParameter.js'; | ||
export { getParameters } from './getParameters.js'; | ||
export { getParametersByName } from './getParametersByName.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { DEFAULT_PROVIDERS } from '../base/DefaultProviders.js'; | ||
import type { SSMSetOptions } from '../types/SSMProvider'; | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { SSMProvider } from './SSMProvider'; | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* ## Intro | ||
* The Parameters utility provides an SSMProvider that allows setting parameters in AWS Systems Manager. | ||
* | ||
* ## Getting started | ||
* | ||
* This utility supports AWS SDK v3 for JavaScript only. This allows the utility to be modular, and you to install only | ||
* the SDK packages you need and keep your bundle size small. | ||
* | ||
* To use the provider, you must install the Parameters utility and the AWS SDK v3 for JavaScript for SSM: | ||
* | ||
* ```sh | ||
* npm install @aws-lambda-powertools/parameters @aws-sdk/client-ssm | ||
*``` | ||
* | ||
* ## Basic Usage | ||
* | ||
* @example | ||
* ```typescript | ||
* import { setParameter } from '@aws-lambda-powertools/parameters/ssm'; | ||
* | ||
* export const handler = async (): Promise<void> => { | ||
* // Set a parameter | ||
* const version = await setParameter('/my-parameter', { value: 'my-value' }); | ||
* console.log(Parameter version: ${version}); | ||
* }; | ||
* ``` | ||
* | ||
* ## Advanced Usage | ||
* | ||
* ### Overwriting a parameter | ||
* | ||
* By default, the provider will not overwrite a parameter if it already exists. You can force the provider to overwrite the parameter by using the `overwrite` option. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { setParameter } from '@aws-lambda-powertools/parameters/ssm'; | ||
* | ||
* export const handler = async (): Promise<void> => { | ||
* // Set a parameter and overwrite it | ||
* const version = await setParameter('/my-parameter', { | ||
* value: 'my-value', | ||
* overwrite: true, | ||
* }); | ||
* console.log(Parameter version: ${version}); | ||
* }; | ||
* ``` | ||
* | ||
* ### Extra SDK options | ||
* | ||
* When setting a parameter, you can pass extra options to the AWS SDK v3 for JavaScript client by using the sdkOptions parameter. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { setParameter } from '@aws-lambda-powertools/parameters/ssm'; | ||
* | ||
* export const handler = async (): Promise<void> => { | ||
* // Set a parameter with extra options | ||
* const version = await setParameter('/my-parameter', { | ||
* value: 'my-value', | ||
* sdkOptions: { | ||
* Overwrite: true, | ||
* }, | ||
* }); | ||
* }; | ||
* ``` | ||
* | ||
* This object accepts the same options as the AWS SDK v3 for JavaScript `PutParameterCommandInput` interface. | ||
* | ||
* ### Built-in provider class | ||
* | ||
* For greater flexibility such as configuring the underlying SDK client used by built-in providers, you can use the {@link SSMProvider} class. | ||
* | ||
* ### Options | ||
* | ||
* You can customize the storage of the value by passing options to the function: | ||
* * `value` - The value of the parameter, which is a mandatory option. | ||
* * `overwrite` - Whether to overwrite the value if it already exists (default: `false`) | ||
* * `description` - The description of the parameter | ||
* * `parameterType` - The type of the parameter, can be one of `String`, `StringList`, or `SecureString` (default: `String`) | ||
* * `tier` - The parameter tier to use, can be one of `Standard`, `Advanced`, and `Intelligent-Tiering` (default: `Standard`) | ||
* * `kmsKeyId` - The KMS key id to use to encrypt the parameter | ||
* * `sdkOptions` - Extra options to pass to the AWS SDK v3 for JavaScript client | ||
* | ||
* For more usage examples, see [our documentation](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parameters/). | ||
* | ||
* @param {string} name - Name of the parameter | ||
* @param {SSMSetOptions} options - Options to configure the parameter | ||
* @see https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parameters/ | ||
*/ | ||
const setParameter = async < | ||
InferredFromOptionsType extends SSMSetOptions | undefined = SSMSetOptions, | ||
>( | ||
name: string, | ||
options: InferredFromOptionsType & SSMSetOptions | ||
): Promise<number | undefined> => { | ||
if (!Object.hasOwn(DEFAULT_PROVIDERS, 'ssm')) { | ||
DEFAULT_PROVIDERS.ssm = new SSMProvider(); | ||
} | ||
return (DEFAULT_PROVIDERS.ssm as SSMProvider).set(name, options); | ||
}; | ||
|
||
export { setParameter }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.