Having got x-acct pull working for my lambda function, in staging, I had foolishly assumed that running the same CDK script for prod would be easy (as that is the same account where the ECR lives).
Instead the build was failing, with a confusing message:
14:52:31 MyStack | 4/11 | 1:52:29 PM | CREATE_FAILED | AWS::Lambda::Function | MyLambda (MyLambda...) Resource handler returned message: "Source image ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/REPO:latest is not valid. Provide a valid source image. (Service: Lambda, Status Code: 400, Request ID: ...) (SDK Attempt Count: 1)" (RequestToken: ..., HandlerErrorCode: InvalidRequest)
Obviously, the ECR uri is valid, or it wouldn’t be working in the other account. I assumed it was permissions related, but the permissions I had added for x-acct seemed to be a superset of the permissions necessary within the same account.
When I tried to create the lambda in the console, a slightly more useful error was returned. It seems that Lambda is unable to pull from ECR in another region (even though Fargate has no trouble). The easiest solution to this, is to enable replication.
You can do this in the cloudformation to create the repo:
Resources:
RepositoryReplicationConfig:
Type: AWS::ECR::ReplicationConfiguration
Properties:
ReplicationConfiguration:
Rules:
- Destinations:
- Region: ...
RegistryId: ... (account id)
