Package software.amazon.awscdk.services.ssm
AWS Systems Manager Construct Library
This module is part of the AWS Cloud Development Kit project.
Using existing SSM Parameters in your CDK app
You can reference existing SSM Parameter Store values that you want to use in
your CDK app by using ssm.StringParameter.fromStringParameterAttributes:
Number parameterVersion = Token.asNumber(Map.of("Ref", "MyParameter"));
// Retrieve the latest value of the non-secret parameter
// with name "/My/String/Parameter".
String stringValue = StringParameter.fromStringParameterAttributes(this, "MyValue", StringParameterAttributes.builder()
.parameterName("/My/Public/Parameter")
.build()).getStringValue();
String stringValueVersionFromToken = StringParameter.fromStringParameterAttributes(this, "MyValueVersionFromToken", StringParameterAttributes.builder()
.parameterName("/My/Public/Parameter")
// parameter version from token
.version(parameterVersion)
.build()).getStringValue();
// Retrieve a specific version of the secret (SecureString) parameter.
// 'version' is always required.
IStringParameter secretValue = StringParameter.fromSecureStringParameterAttributes(this, "MySecureValue", SecureStringParameterAttributes.builder()
.parameterName("/My/Secret/Parameter")
.version(5)
.build());
IStringParameter secretValueVersionFromToken = StringParameter.fromSecureStringParameterAttributes(this, "MySecureValueVersionFromToken", SecureStringParameterAttributes.builder()
.parameterName("/My/Secret/Parameter")
// parameter version from token
.version(parameterVersion)
.build());
You can also reference an existing SSM Parameter Store value that matches an AWS specific parameter type:
StringParameter.valueForTypedStringParameterV2(this, "/My/Public/Parameter", ParameterValueType.AWS_EC2_IMAGE_ID);
To do the same for a SSM Parameter Store value that is stored as a list:
StringListParameter.valueForTypedListParameter(this, "/My/Public/Parameter", ParameterValueType.AWS_EC2_IMAGE_ID);
Lookup existing parameters
You can also use an existing parameter by looking up the parameter from the AWS environment. This method uses AWS API calls to lookup the value from SSM during synthesis.
String stringValue = StringParameter.valueFromLookup(this, "/My/Public/Parameter");
The result of the StringParameter.valueFromLookup() operation will be written to a file
called cdk.context.json. You must commit this file to source control so
that the lookup values are available in non-privileged environments such
as CI build steps, and to ensure your template builds are repeatable.
To customize the cache key, use the additionalCacheKey property of the options parameter.
This allows you to have multiple lookups with the same parameters
cache their values separately. This can be useful if you want to
scope the context variable to a construct (ie, using additionalCacheKey: this.node.path),
so that if the value in the cache needs to be updated, it does not need to be updated
for all constructs at the same time.
String stringValue = StringParameter.valueFromLookup(this, "/My/Public/Parameter", undefined, StringParameterLookupOptions.builder().additionalCacheKey(this.node.getPath()).build());
When using valueFromLookup an initial value of 'dummy-value-for-${parameterName}'
(dummy-value-for-/My/Public/Parameter in the above example)
is returned prior to the lookup being performed. This can lead to errors if you are using this
value in places that require a certain format. For example if you have stored the ARN for a SNS
topic in a SSM Parameter which you want to lookup and provide to Topic.fromTopicArn()
String arnLookup = StringParameter.valueFromLookup(this, "/my/topic/arn"); Topic.fromTopicArn(this, "Topic", arnLookup);
Initially arnLookup will be equal to dummy-value-for-/my/topic/arn which will cause
Topic.fromTopicArn to throw an error indicating that the value is not in arn format.
For these use cases you need to handle the dummy-value in your code. For example:
String arnLookup = StringParameter.valueFromLookup(this, "/my/topic/arn");
String arnLookupValue;
if (arnLookup.includes("dummy-value")) {
arnLookupValue = this.formatArn(ArnComponents.builder()
.service("sns")
.resource("topic")
.resourceName(arnLookup)
.build());
} else {
arnLookupValue = arnLookup;
}
Topic.fromTopicArn(this, "Topic", arnLookupValue);
Alternatively, if the property supports tokens you can convert the parameter value into a token to be resolved after the lookup has been completed.
String arnLookup = StringParameter.valueFromLookup(this, "/my/role/arn");
Role.fromRoleArn(this, "role", Lazy.string(Map.of("produce", () => arnLookup)));
cross-account SSM Parameters sharing
AWS Systems Manager (SSM) Parameter Store supports cross-account sharing of parameters using the AWS Resource Access Manager (AWS RAM)
service. In a multi-account environment, this feature enables accounts (referred to as "consuming accounts") to access and retrieve
parameter values that are shared by other accounts (referred to as "sharing accounts"). To reference and use a shared SSM parameter
in a consuming account, the fromStringParameterArn() method can be employed.
The fromStringParameterArn() method provides a way for consuming accounts to create an instance of the StringParameter
class from the Amazon Resource Name (ARN) of a shared SSM parameter. This allows the consuming account to retrieve and utilize the
parameter value, even though the parameter itself is owned and managed by a different sharing account.
String sharingParameterArn = "arn:aws:ssm:us-east-1:1234567890:parameter/dummyName"; IStringParameter sharedParam = StringParameter.fromStringParameterArn(this, "SharedParam", sharingParameterArn);
Things to note:
- The account that owns the AWS Systems Manager (SSM) parameter and wants to share it with other accounts (referred to as the "sharing account") must create the parameter in the advanced tier. This is a prerequisite for sharing SSM parameters across accounts.
- After creating the parameter in the advanced tier, the sharing account needs to set up a resource share using AWS Resource Access Manager (RAM). This resource share will specify the SSM parameter(s) to be shared and the accounts (referred to as "consuming accounts") with which the parameter(s) should be shared.
- Once the resource share is created by the sharing account, the consuming account(s) will receive an invitation to join the resource share. For the consuming account(s) to access and use the shared SSM parameter(s), they must accept the resource share invitation from the sharing account.
- The AWS Systems Manager Parameter Store parameter being referenced must be located in the same AWS region as the AWS CDK stack that is consuming or using the parameter.
In summary, the process involves three main steps:
- The sharing account creates the SSM parameter(s) in the advanced tier.
- The sharing account creates a resource share using AWS RAM, specifying the SSM parameter(s) and the consuming account(s).
- The consuming account(s) accept the resource share invitation to gain access to the shared SSM parameter(s).
This cross-account sharing mechanism allows for centralized management and distribution of configuration data (stored as SSM parameters) across multiple AWS accounts within an organization or between different organizations.
Read Working with shared parameters for more details.
Creating new SSM Parameters in your CDK app
You can create either ssm.StringParameter or ssm.StringListParameters in
a CDK app. These are public (not secret) values. Parameters of type
SecureString cannot be created directly from a CDK application; if you want
to provision secrets automatically, use Secrets Manager Secrets (see the
aws-cdk-lib/aws-secretsmanager package).
StringParameter.Builder.create(this, "Parameter")
.allowedPattern(".*")
.description("The value Foo")
.parameterName("FooParameter")
.stringValue("Foo")
.tier(ParameterTier.ADVANCED)
.build();
// Grant read access to some Role
IRole role;
// Create a new SSM Parameter holding a String
StringParameter param = StringParameter.Builder.create(this, "StringParameter")
// description: 'Some user-friendly description',
// name: 'ParameterName',
.stringValue("Initial parameter value")
.build();
param.grantRead(role);
// Create a new SSM Parameter holding a StringList
StringListParameter listParameter = StringListParameter.Builder.create(this, "StringListParameter")
// description: 'Some user-friendly description',
// name: 'ParameterName',
.stringListValue(List.of("Initial parameter value A", "Initial parameter value B"))
.build();
When specifying an allowedPattern, the values provided as string literals
are validated against the pattern and an exception is raised if a value
provided does not comply.
Using Tokens in parameter name
When using CDK Tokens in parameter name,
you need to explicitly set the simpleName property. Setting simpleName to an incorrect boolean
value may result in unexpected behaviours, such as having duplicate '/' in the parameter ARN
or missing a '/' in the parameter ARN.
simpleName is used to indicates whether the parameter name is a simple name. A parameter name
without any '/' is considered a simple name, thus you should set simpleName to true.
If the parameter name includes '/', set simpleName to false.
import software.amazon.awscdk.services.lambda.*;
IFunction func;
StringParameter simpleParameter = StringParameter.Builder.create(this, "StringParameter")
// the parameter name doesn't contain any '/'
.parameterName("parameter")
.stringValue("SOME_VALUE")
.simpleName(true)
.build();
StringParameter nonSimpleParameter = StringParameter.Builder.create(this, "StringParameter")
// the parameter name contains '/'
.parameterName(String.format("/%s/my/app/param", func.getFunctionName()))
.stringValue("SOME_VALUE")
.simpleName(false)
.build();
-
ClassDescriptionThe
AWS::SSM::Associationresource creates a State Manager association for your managed instances.A fluent builder forCfnAssociation.InstanceAssociationOutputLocationis a property of the AWS::SSM::Association resource that specifies an Amazon S3 bucket where you want to store the results of this association request.A builder forCfnAssociation.InstanceAssociationOutputLocationPropertyAn implementation forCfnAssociation.InstanceAssociationOutputLocationPropertyS3OutputLocationis a property of the AWS::SSM::Association resource that specifies an Amazon S3 bucket where you want to store the results of this association request.A builder forCfnAssociation.S3OutputLocationPropertyAn implementation forCfnAssociation.S3OutputLocationPropertyTargetis a property of the AWS::SSM::Association resource that specifies the targets for an SSM document in Systems Manager .A builder forCfnAssociation.TargetPropertyAn implementation forCfnAssociation.TargetPropertyProperties for defining aCfnAssociation.A builder forCfnAssociationPropsAn implementation forCfnAssociationPropsTheAWS::SSM::Documentresource creates a Systems Manager (SSM) document in AWS Systems Manager .Identifying information about a document attachment, including the file name and a key-value pair that identifies the location of an attachment to a document.A builder forCfnDocument.AttachmentsSourcePropertyAn implementation forCfnDocument.AttachmentsSourcePropertyA fluent builder forCfnDocument.An SSM document required by the current document.A builder forCfnDocument.DocumentRequiresPropertyAn implementation forCfnDocument.DocumentRequiresPropertyProperties for defining aCfnDocument.A builder forCfnDocumentPropsAn implementation forCfnDocumentPropsTheAWS::SSM::MaintenanceWindowresource represents general information about a maintenance window for AWS Systems Manager .A fluent builder forCfnMaintenanceWindow.Properties for defining aCfnMaintenanceWindow.A builder forCfnMaintenanceWindowPropsAn implementation forCfnMaintenanceWindowPropsTheAWS::SSM::MaintenanceWindowTargetresource registers a target with a maintenance window for AWS Systems Manager .A fluent builder forCfnMaintenanceWindowTarget.TheTargetsproperty type specifies adding a target to a maintenance window target in AWS Systems Manager .A builder forCfnMaintenanceWindowTarget.TargetsPropertyAn implementation forCfnMaintenanceWindowTarget.TargetsPropertyProperties for defining aCfnMaintenanceWindowTarget.A builder forCfnMaintenanceWindowTargetPropsAn implementation forCfnMaintenanceWindowTargetPropsTheAWS::SSM::MaintenanceWindowTaskresource defines information about a task for an AWS Systems Manager maintenance window.A fluent builder forCfnMaintenanceWindowTask.Configuration options for sending command output to Amazon CloudWatch Logs.A builder forCfnMaintenanceWindowTask.CloudWatchOutputConfigPropertyAn implementation forCfnMaintenanceWindowTask.CloudWatchOutputConfigPropertyA builder forCfnMaintenanceWindowTask.LoggingInfoPropertyAn implementation forCfnMaintenanceWindowTask.LoggingInfoPropertyTheMaintenanceWindowAutomationParametersproperty type specifies the parameters for anAUTOMATIONtask type for a maintenance window task in AWS Systems Manager .An implementation forCfnMaintenanceWindowTask.MaintenanceWindowAutomationParametersPropertyTheMaintenanceWindowLambdaParametersproperty type specifies the parameters for aLAMBDAtask type for a maintenance window task in AWS Systems Manager .An implementation forCfnMaintenanceWindowTask.MaintenanceWindowLambdaParametersPropertyTheMaintenanceWindowRunCommandParametersproperty type specifies the parameters for aRUN_COMMANDtask type for a maintenance window task in AWS Systems Manager .An implementation forCfnMaintenanceWindowTask.MaintenanceWindowRunCommandParametersPropertyTheMaintenanceWindowStepFunctionsParametersproperty type specifies the parameters for the execution of aSTEP_FUNCTIONStask in a Systems Manager maintenance window.An implementation forCfnMaintenanceWindowTask.MaintenanceWindowStepFunctionsParametersPropertyTheNotificationConfigproperty type specifies configurations for sending notifications for a maintenance window task in AWS Systems Manager .A builder forCfnMaintenanceWindowTask.NotificationConfigPropertyAn implementation forCfnMaintenanceWindowTask.NotificationConfigPropertyTheTargetproperty type specifies targets (either instances or window target IDs).A builder forCfnMaintenanceWindowTask.TargetPropertyAn implementation forCfnMaintenanceWindowTask.TargetPropertyTheTaskInvocationParametersproperty type specifies the task execution parameters for a maintenance window task in AWS Systems Manager .An implementation forCfnMaintenanceWindowTask.TaskInvocationParametersPropertyProperties for defining aCfnMaintenanceWindowTask.A builder forCfnMaintenanceWindowTaskPropsAn implementation forCfnMaintenanceWindowTaskPropsTheAWS::SSM::Parameterresource creates an SSM parameter in AWS Systems Manager Parameter Store.A fluent builder forCfnParameter.Properties for defining aCfnParameter.A builder forCfnParameterPropsAn implementation forCfnParameterPropsTheAWS::SSM::PatchBaselineresource defines the basic information for an AWS Systems Manager patch baseline.A fluent builder forCfnPatchBaseline.ThePatchFilterGroupproperty type specifies a set of patch filters for an AWS Systems Manager patch baseline, typically used for approval rules for a Systems Manager patch baseline.A builder forCfnPatchBaseline.PatchFilterGroupPropertyAn implementation forCfnPatchBaseline.PatchFilterGroupPropertyThePatchFilterproperty type defines a patch filter for an AWS Systems Manager patch baseline.A builder forCfnPatchBaseline.PatchFilterPropertyAn implementation forCfnPatchBaseline.PatchFilterPropertyA builder forCfnPatchBaseline.PatchSourcePropertyAn implementation forCfnPatchBaseline.PatchSourcePropertyTheRuleGroupproperty type specifies a set of rules that define the approval rules for an AWS Systems Manager patch baseline.A builder forCfnPatchBaseline.RuleGroupPropertyAn implementation forCfnPatchBaseline.RuleGroupPropertyTheRuleproperty type specifies an approval rule for a Systems Manager patch baseline.A builder forCfnPatchBaseline.RulePropertyAn implementation forCfnPatchBaseline.RulePropertyProperties for defining aCfnPatchBaseline.A builder forCfnPatchBaselinePropsAn implementation forCfnPatchBaselinePropsTheAWS::SSM::ResourceDataSyncresource creates, updates, or deletes a resource data sync for AWS Systems Manager .Information about theAwsOrganizationsSourceresource data sync source.A builder forCfnResourceDataSync.AwsOrganizationsSourcePropertyAn implementation forCfnResourceDataSync.AwsOrganizationsSourcePropertyA fluent builder forCfnResourceDataSync.Information about the target S3 bucket for the resource data sync.A builder forCfnResourceDataSync.S3DestinationPropertyAn implementation forCfnResourceDataSync.S3DestinationPropertyInformation about the source of the data included in the resource data sync.A builder forCfnResourceDataSync.SyncSourcePropertyAn implementation forCfnResourceDataSync.SyncSourcePropertyProperties for defining aCfnResourceDataSync.A builder forCfnResourceDataSyncPropsAn implementation forCfnResourceDataSyncPropsCreates or updates a Systems Manager resource policy.A fluent builder forCfnResourcePolicy.Properties for defining aCfnResourcePolicy.A builder forCfnResourcePolicyPropsAn implementation forCfnResourcePolicyPropsCommon attributes for string parameters.A builder forCommonStringParameterAttributesAn implementation forCommonStringParameterAttributesAn SSM Parameter reference.Internal default implementation forIParameter.A proxy class which represents a concrete javascript instance of this type.A StringList SSM Parameter.Internal default implementation forIStringListParameter.A proxy class which represents a concrete javascript instance of this type.A String SSM Parameter.Internal default implementation forIStringParameter.A proxy class which represents a concrete javascript instance of this type.Attributes for parameters of string list type.A builder forListParameterAttributesAn implementation forListParameterAttributesSSM parameter data type.Properties needed to create a new SSM Parameter.A builder forParameterOptionsAn implementation forParameterOptionsSSM parameter tier.Deprecated.these types are no longer usedThe type of CFN SSM Parameter.Attributes for secure string parameters.A builder forSecureStringParameterAttributesAn implementation forSecureStringParameterAttributesCreates a new StringList SSM Parameter.A fluent builder forStringListParameter.Properties needed to create a StringList SSM Parameter.A builder forStringListParameterPropsAn implementation forStringListParameterPropsCreates a new String SSM Parameter.A fluent builder forStringParameter.Attributes for parameters of various types of string.A builder forStringParameterAttributesAn implementation forStringParameterAttributesAdditional properties for looking up an existing StringParameter.A builder forStringParameterLookupOptionsAn implementation forStringParameterLookupOptionsProperties needed to create a String SSM parameter.A builder forStringParameterPropsAn implementation forStringParameterProps