aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.5k stars 3.84k forks source link

[aws-ssm] - Retrieve parameters with path and region #11039

Open ciaransweet opened 3 years ago

ciaransweet commented 3 years ago

I'd like to be able to get references/retrieve parameters via their path and region. I can currently do similar to this with S3 Buckets with: Bucket.from_bucket_attributes.

However when I look at a similar method for SSM parameters StringParameter.from_string_parameter_attributes I am unable to pass region as a argument. I am also limited to specifying the one name. I would like a similar implementation to Boto3s get_parameters_by_path which enables a wildcard approach to finding parameters.

Ideally I would like to do something like:

params = StringParameter.from_string_parameter_attributes(path="/my/path/", region="us-west-2")

Use Case

So my scenario is:

An external project can create n randomly named buckets in a region - it stores the names of these buckets under deterministic keys in Parameter Store eg (/project/stage/bucket-name-1)

My stack (in a different region) - wants to import those buckets (use them as references), so I currently do this by using Boto3 and getting the parameters under /project/stage/ - Doing this gives me the randomly generated bucket names. Then I can use s3.Bucket.from_bucket_attributes with the bucket name and the region the bucket was created in, to import those buckets as references into my stack.

This is working, but when I do another deploy (without changing anything) - these references are totally different objects (but still point to the same buckets) so I always have changes according to CDK.

I'd like my proposed features implemented so that I can import SSM parameters in a CDK-style manner, so that my further deploys (with no changes) indicate nothing is different.

Other

I'm unsure if this is just the CDK which needs this implemented or CloudFormation itself. I see that CfnParameterProps makes no mention of region either.

Happy to raise this elsewhere if it belongs in a better place!


This is a :rocket: Feature Request

Jacco commented 1 year ago

I think this needs an adjusted contextProvider for the fromLookup for parameters. The value that can be referenced from the fromAttributes ones can only work in the same region because they use a CfnDynamicReference or a CfnParameter which do not support cross region.

corymhall commented 1 year ago

@ciaranevans is this still relevant? The first argument to from_string_parameter_attributes is the scope which you could provide the region in.

stack = Stack(app, 'MyStack', env=Environment(region='us-east-1' ));
params = StringParameter.from_string_parameter_attributes(stack, "my-param", parameter_name="/my/path")
ciaransweet commented 1 year ago

@corymhall - firstly, probably not relevant for me... I raised it 3 years ago 😅 however, it has 44 other folks that reacted, so I imagine so.

Also, I don't think importing a stack just for the sake of being able to use its region is best, like my original post asked, it would be ideal if it just behaved the same as buckets. Those didn't require the separate import of a stack.

But, full disclosure, I don't touch CDK anymore 😭 so things have probably changed a lot.

github-actions[bot] commented 2 months ago

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.