I would like to launch an ECS fargate TASK while granting dynamic permissions on the container. More specifically, I want the container to be able to access a single file in s3, which I only know about at runtime.
I tried to use sts:GetFederationToken to achieve the following (spoiler, it doesn't work):
- lambda gets called with some
fileName - lambda calls
GetFederationTokenwith policy restriction on the specific s3 file - Obtain tokens and pass them to the container (using container overrides)
Unfortunately, this does not work and I'm stuck with the following error:
AccessDenied: Cannot call GetFederationToken with session credentials
From what I now understand, it appears that lambda is already using a temp session, and can therefore not call sts:GetFederationToken.
Is there any way to achieve what I'm trying to do here ? To recap, I would like a lambda to launch a fargate task that has access rights on a specific s3 file. I cannot know the s3 file in advance (i.e. I cannot create a proper policy beforehand)
EDIT
To clarify things a bit more:
- I can NOT know the file name before the lambda is called. The file name depends on user parameters, and is sent to the lambda by the user, at runtime
- Multiple containers will run at the same time, and no container should have permission to see anything else than its own legit file (i.e. containers cannot be trusted)

