Skip to content
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

aws-ssm: StringParameter Doesn't support data_type=ssm.ParameterType.AWS_EC2_IMAGE_ID #16806

Closed
scottbisker opened this issue Oct 5, 2021 · 2 comments · Fixed by #16884
Closed
Labels
@aws-cdk/aws-ssm Related to AWS Systems Manager bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@scottbisker
Copy link

What is the problem?

When trying to create a StringParameter of type ssm.ParameterType.AWS_EC2_IMAGE_ID, CDK throws the following error.

1 validation error detected: Value 'AWS::EC2::Image::Id' at 'type' failed to satisfy constraint: Member must satisfy enum value set: [SecureString, StringList, String]. (Service: AmazonSSM; Status Code: 400; Error Code: Validat
ionException; Request ID: 2c97174a-045e-4451-be0a-b61d8f5a2fe8; Proxy: null)

Reproduction Steps

image_parameter = ssm.StringParameter(self, 'ImageBuilderAMI',
type = ssm.ParameterType.AWS_EC2_IMAGE_ID,
parameter_name = '/ec2-imagebuilder/latest',
description = "Latest AMI Image",
string_value = self.node.try_get_context(env_context)["LinuxAmi"]
)

What did you expect to happen?

Since it is StringParameter, there should be an additional value passed in the constructor data_type.

This is a working version using ssm.CfnParameter.

    image_parameter = ssm.CfnParameter(self, "ImageBuilderAMI",
        type = "String",
        data_type = "aws:ec2:image",
        name = "/ec2-imagebuilder/latest",
        description = "Latest AMI Image",
        value = self.node.try_get_context(env_context)["LinuxAmi"] 
        )

What actually happened?

Stack failed to create.

1 validation error detected: Value 'AWS::EC2::Image::Id' at 'type' failed to satisfy constraint: Member must satisfy enum value set: [SecureString, StringList, String]. (Service: AmazonSSM; Status Code: 400; Error Code: Validat
ionException; Request ID: 2c97174a-045e-4451-be0a-b61d8f5a2fe8; Proxy: null)

CDK CLI Version

1.24.0

Framework Version

No response

Node.js Version

14.16.1

OS

MacOS Big Sur

Language

Python

Language Version

3.9

Other information

No response

@scottbisker scottbisker added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 5, 2021
@github-actions github-actions bot added the @aws-cdk/aws-ssm Related to AWS Systems Manager label Oct 5, 2021
@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Oct 5, 2021
@peterwoodworth
Copy link
Contributor

Thanks for reporting this! The only accepted values for AWS::SSM::Parameter.Type are String or StringList.

The CDK wants you to use an enum ParameterType to specify the type on the StringParameter construct, but then it will directly use this value for the AWS::SSM::Parameter.Type, which will reject this value at deploy time.

const resource = new ssm.CfnParameter(this, 'Resource', {
allowedPattern: props.allowedPattern,
description: props.description,
name: this.physicalName,
tier: props.tier,
type: props.type || ParameterType.STRING,
value: props.stringValue,
});

@peterwoodworth peterwoodworth added effort/small Small work item – less than a day of effort p1 labels Oct 5, 2021
@njlynch njlynch removed their assignment Oct 7, 2021
@mergify mergify bot closed this as completed in #16884 Oct 13, 2021
mergify bot pushed a commit that referenced this issue Oct 13, 2021
…ype (#16884)

Fixes #16806. Now, setting `type: ssm.ParameterType.AWS_EC2_IMAGE_ID` throws an error and instead, you can set `dataType: 'aws:ec2:image'`. Specifically, the `ssm.ParameterType.AWS_EC2_IMAGE_ID` value is used internally (original [PR](#4161)) in a few places and really shouldn't be exposed to the customer. But I'm not sure what else we can do, especially since this is a stable module.

Original code using `CfnParameter`: 
```ts
const parameter = ssm.CfnParameter(this, "ImageBuilderAMI", {
  type: "String",
  dataType: "aws:ec2:image",
  name: "/ec2-imagebuilder/latest",
  description: "Latest AMI Image",
  value: self.node.try_get_context(env_context)["LinuxAmi"] 
});
```

Can now use `StringParameter`: 
```ts
const parameter = ssm.StringParameter(this, 'ImageBuilderAMI', {
  dataType: 'aws:ec2:image',
  parameterName: '/ec2-imagebuilder/latest',
  description: "Latest AMI Image",
  stringValue: self.node.try_get_context(env_context)["LinuxAmi"]
});
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…ype (aws#16884)

Fixes aws#16806. Now, setting `type: ssm.ParameterType.AWS_EC2_IMAGE_ID` throws an error and instead, you can set `dataType: 'aws:ec2:image'`. Specifically, the `ssm.ParameterType.AWS_EC2_IMAGE_ID` value is used internally (original [PR](aws#4161)) in a few places and really shouldn't be exposed to the customer. But I'm not sure what else we can do, especially since this is a stable module.

Original code using `CfnParameter`: 
```ts
const parameter = ssm.CfnParameter(this, "ImageBuilderAMI", {
  type: "String",
  dataType: "aws:ec2:image",
  name: "/ec2-imagebuilder/latest",
  description: "Latest AMI Image",
  value: self.node.try_get_context(env_context)["LinuxAmi"] 
});
```

Can now use `StringParameter`: 
```ts
const parameter = ssm.StringParameter(this, 'ImageBuilderAMI', {
  dataType: 'aws:ec2:image',
  parameterName: '/ec2-imagebuilder/latest',
  description: "Latest AMI Image",
  stringValue: self.node.try_get_context(env_context)["LinuxAmi"]
});
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ssm Related to AWS Systems Manager bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants