Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot sam local start-api without specifying an image #7062

Open
maxhayward opened this issue May 14, 2024 · 1 comment
Open

Cannot sam local start-api without specifying an image #7062

maxhayward opened this issue May 14, 2024 · 1 comment

Comments

@maxhayward
Copy link

Running sam local start-api with PackageType: Image but not specifying an ImageUri gives the following error:

samcli.commands.local.lib.exceptions.InvalidIntermediateImageError: ImageUri not provided for Function: UserFunction of PackageType: Image

But this documentation excerpt (Example 2) implies that it should be possible.

I see this issue is mentioned previously and from my understanding, even when building the image locally, we still need to specify ImageUri in either case. Is this correct? If so, does the documentation need updating?

@maxhayward maxhayward added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label May 14, 2024
@mndeveci
Copy link
Contributor

Hey @maxhayward,

You need to build your function locally in order to execute it. Building is required if the function type is Image. However if you are using an interpreted language like python and if you are using Zip lambda functions, you can use sam local invoke directly (however this one will also fail if you have external dependencies).

When you first run sam init and instantiate the application template, you should see that ImageUri is missing in the template. Instead it contains build time parameters which is required to build your function locally (like DockerTag which will be used to tag image locally).

After you run sam build locally, you can check built template under .aws-sam/build/template.yaml and you can see that it has ImageUri field with some values which is pointing to locally build image (eg. helloworldfunction:python3.12-v1).

tl;dr sam local invoke needs everything to be ready before executing the function locally. We can update our error message to ask users to run sam build which could help them to fix this issue.

@mndeveci mndeveci added type/question area/local and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants