Skip to content

Instantly share code, notes, and snippets.

@NickDarvey
Created November 18, 2021 03:30
Show Gist options
  • Save NickDarvey/f1a508d5bbdd4a982da729fa661a36e9 to your computer and use it in GitHub Desktop.
Save NickDarvey/f1a508d5bbdd4a982da729fa661a36e9 to your computer and use it in GitHub Desktop.
Cross-region reading of SSM parameter values.
open Constructs
open Amazon.CDK.CustomResources
type SSMParameterReaderProps
(
ParameterName : string,
Region: string
) =
member _.ParameterName = ParameterName
member _.Region = Region
/// Cross-region reading of SSM parameter values.
// Based on
// - https://stackoverflow.com/a/59774628/1259408
// - https://docs.aws.amazon.com/cdk/api/latest/docs/custom-resources-readme.html#get-the-latest-version-of-a-secure-ssm-parameter
type SSMParameterReader(scope : Construct, id : string, props : SSMParameterReaderProps) =
inherit AwsCustomResource(scope, id,
AwsCustomResourceProps(
Policy =
AwsCustomResourcePolicy.FromSdkCalls(
SdkCallsPolicyOptions(
Resources = AwsCustomResourcePolicy.ANY_RESOURCE
)
),
OnUpdate =
AwsSdkCall(
Service = "SSM",
Action = "getParameter",
Parameters = dict [
"Name", props.ParameterName
],
Region = props.Region,
// Update physical id to always fetch the latest version
PhysicalResourceId = PhysicalResourceId.Of(System.DateTime.Now.ToString("o"))
)
)
)
member this.GetParameterValue() = this.GetResponseField("Parameter.Value")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment