aws-cdk-lib/aws-ec2: cfnInstance does not attach instance profile #19978
-
Describe the bugI am writing a CDK app in typescript. I am using the ec2.CfnInstance construct because it exposes more options than ec2.Instance When passing a instance profile name to iamInstanceProfile of the construction props, the resulting instance does not have a role attached to it. Expected BehaviorAfter launching my cdk stack I would expect and instance profile association with my instance id Current BehaviorNo association exists, eg:
Reproduction StepsLaunch a cdk typescript app with the following construct snippet
Possible SolutionNo response Additional Information/ContextNo response CDK CLI Version2.20.0 (build 738ef49) Framework VersionNo response Node.js Versionv16.10.0 OSMacOS LanguageTypescript Language VersionTypeScript 4.6.3 Other informationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @ahfx, I've managed to reproduce this. Our CfnInstanceProfile class does have the instanceProfileName property, but it would only be set if you define that property since that's one of the input properties to the CfnInstanceProfile construct. If you desire to return the name of the CfnInstanceProfile (which won't be set at synthesis) use The way you're doing it now, the template isn't outputting anything at all for the IamInstanceProfile property, so that's why you're not running into any errors. |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Hey @ahfx, I've managed to reproduce this.
Our CfnInstanceProfile class does have the instanceProfileName property, but it would only be set if you define that property since that's one of the input properties to the CfnInstanceProfile construct.
If you desire to return the name of the CfnInstanceProfile (which won't be set at synthesis) use
cfnInstanceProfile.ref
here instead. This fixed the issue for meThe way you're doing it now, the template isn't outputting anything at all for the IamInstanceProfile property, so that's why you're not running into any errors.