Hi there, I'm trying to pass an image created by t...
# aws
l
Hi there, I'm trying to pass an image created by the ecr repository
buildAndPushImage
function to the container image parameter in a
aws.ecs.TaskDefinition
container definition block and keep running into this error
Container.image repository should be 255 characters or less
. This seems to happen with any Output<string> type. Is this a known issue?
q
This is most likely not a bug but you're most likely using an
Output<string>
in a place where only
string
is accepted, which will cause the
Output<string>
to be rendered as an error message telling you that you're calling
toString
on an unresolved
Output
, which is likely to be > 255 characters. If the place where you use only accepts
string
and not
Output<string>
, you need to call
apply
on the
Output<string>
to perform the action on the
string
that the
Output<string>
eventually resolves to asynchronously, e.g.:
Copy code
const imageOutput: Output<string> = ...
imageOutput.apply((image: string) => {
  // do something with image, which is the string the imageOutput resolves to
})
Hope that helps!
r
I know this is old, but… IMO bug or not, this is a real usability issue. If you cannot reliably produce a normal string from an Output before its value is used (me, I am using it as part of the
image
name in a task definition file, and it just flatly refuses to accept the ecr repository’s
.repository_url
, even if I try to use
apply
on it), what good is it?
b
…you can do this. You’re likely using the
apply
wrong
can you share your code
r
ok based on https://www.pulumi.com/docs/intro/concepts/inputs-outputs/, I’ve been doing the apply directly on the output:
Copy code
repository = aws.ecr.Repository(...)

task_definition = aws.ecs.TaskDefinition(...
  container_definitions = json.dumps(
    [
      {
        'image': repository.repository_url.apply(lambda v: f'{ v }'),
        ...
      }
    ]
  ),
  ...
)
which gives me
TypeError: Object of type Output is not JSON serializable
b
You need to do it outside the json.dumps call
r
I see it and am trying it out now. Honestly I would never really have thought about doing it this way
it works! been frustrated with this one. Thanks