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.4k stars 3.8k forks source link

aws-ssm: Allow creating parameters from a full ARN #30790

Open doublecompile opened 2 weeks ago

doublecompile commented 2 weeks ago

Describe the feature

As it stands today, the StringParameter class assumes parameter names given to fromStringParameterAttributes are in the same account as the containing stack.

Please introduce support for providing a pre-existing SSM Parameter Store parameter ARN to create an instance of StringParameter.

Another acceptable implementation might be to add an account property to the StringParameterAttributes interface and alter the logic inside fromStringParameterAttributes to use the full ARN for the CfnParameter default value.

Use Case

SSM Parameter Store introduced cross-account sharing in February 2024. The linked post has the following excerpt:

You can use central AWS accounts to share parameters for many cross-account scenarios, such as referencing centrally managed “golden” AMI IDs in EC2 Launch Templates for autoscaling

This is my exact use case. I have a String Parameter whose data type is aws:ec2:image in account A. The parameter is shared with account B. I have a CloudFormation stack with a Launch Template in account B where I'd like to reference the parameter in account A.

Proposed Solution

Add a new static method named fromStringParameterArn (or something similar) on the StringParameter class. This new method should allow me to provide a full ARN for an SSM Parameter Store parameter that can be used in a CloudFormation stack in a different account.

Other Information

No response

Acknowledgements

CDK version used

2.148.0

Environment details (OS name and version, etc.)

N/A

doublecompile commented 2 weeks ago

The proposed solution should generate CloudFormation template parameters like this working example:

Parameters:
  ImageIdParam:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: arn:aws:ssm:us-east-1:123456789012:parameter/name/of/my/param
pahud commented 1 week ago

related to https://github.com/aws/aws-cdk/pull/30646

Is this something you want?

github-actions[bot] commented 1 week ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

doublecompile commented 1 week ago

@pahud Yes, the pull request you linked will cover my use case. Thanks!