https://pulumi.com logo
#typescript
Title
# typescript
q

quiet-crayon-85132

08/10/2023, 9:21 PM
Hello, I am following the tutorial here: https://www.pulumi.com/docs/clouds/aws/guides/ecr/#consuming-a-private-repository-from-ecs But I get the following error when referencing
image: image.imageUri,
in my taskdefinition. If i hard code the string it works, which is strange. Any guidance? I dont believe ECS has any restrictions on the length of this field:
Copy code
Diagnostics:
    aws:ecs:TaskDefinition (service):
      error: 1 error occurred:
      	* failed creating ECS Task Definition (service-b4d7f7a8): ClientException: Container.image repository should be 255 characters or less.
l

little-cartoon-10569

08/10/2023, 9:26 PM
Based on experience, I'm going to make a guess: your task definition is using a JSON.stringify and image.imageUri is in there without a
pulumi.interpolate
. So your URI is actually a big long error message.
Apologies if I'm way off the mark! It has happened to me, and to many people whose code I have reviewed. So I'm guessing 🙂
q

quiet-crayon-85132

08/10/2023, 9:29 PM
mmm i am not doing a json stringify, im using crosswalk, straight from the example
l

little-cartoon-10569

08/10/2023, 9:35 PM
I'll look in the AWSX code to see what it does. Are you using awsx classic/0.40.1? Or awsx new?
f

full-eve-52536

08/10/2023, 9:36 PM
I'm not sure that pulumi knows what
image.imageUri
is at that point, since technically it's part of `image`s Output
q

quiet-crayon-85132

08/10/2023, 9:36 PM
it is
Copy code
"@pulumi/awsx": "^1.0.0",
l

little-cartoon-10569

08/10/2023, 9:36 PM
It should know. It does in all other cases: that's what outputs are for. However, awsx does not always follow Pulumi's best practices.
f

full-eve-52536

08/10/2023, 9:37 PM
Would the
apply
function be needed here? https://www.pulumi.com/docs/concepts/inputs-outputs/#apply
l

little-cartoon-10569

08/10/2023, 9:38 PM
apply is pulumi.interpolate. It would be needed only if the big JSON object is turning into a string. If it is handled as a complete object and all Input<>s in it are handled correctly, then it should work correctly.
Give me 5 minutes to find and review the code.
q

quiet-crayon-85132

08/10/2023, 9:38 PM
thank you so much!
f

full-eve-52536

08/10/2023, 9:40 PM
the
image:
property expects a string, so it would need to use
interpolate
l

little-cartoon-10569

08/10/2023, 9:46 PM
The documentation uses "string" to mean "Input<string>", so it would be handled correctly if that was all that was involved. (I've complained about that on many occasions, they won't change it back 😞 )
However, that's not all that's involved. There are multiple levels of CustomResource and ComponentResource through the awsx and aws code. It looks like the image property is not used directly: it is put into a ContainerDefinition in the awsx code. Still reading....
However, I don't understand why it's explicitly applying cpu, memory and memoryReservation. What about all the other properties, including image?
Line 152 should do everything that's needed:
Copy code
const containerString = containerDefinitions.apply((d) => JSON.stringify(d));
But.. I'm not convinced. I think you should test this.
And the easiest way is to use apply/interpolate yourself, in your code. If it fixes it, then Alex's/my guesses are correct, and you need to interpolate. So instead of using
image: image.imageUri
, try
Copy code
image: pulumi.interpolate`image.imageUri`
q

quiet-crayon-85132

08/10/2023, 9:52 PM
does it not need the
${}
?
Copy code
image: pulumi.interpolate`${image.imageUri}`,
f

full-eve-52536

08/10/2023, 9:53 PM
I had no idea that some of these resource modules were written that way (with
apply
builtin). You've given me tons of insight @little-cartoon-10569!
q

quiet-crayon-85132

08/10/2023, 9:54 PM
thank you both for the insights
the example on the pulumi documentation is confusing as it has
image: image.imageUri
directly without interpolate, gonna give interpolate a shot
l

little-cartoon-10569

08/10/2023, 9:59 PM
It might do @quiet-crayon-85132. Sorry, been called to a meeting, can't check right now 🙂
q

quiet-crayon-85132

08/10/2023, 9:59 PM
all good, thanks again!
update to close the loop on this, i updated awsx to
1.0.4
from
1.0.1
and it worked, so i guess something was fixed in a recent minor version
3 Views