Open EinarasGar opened 2 years ago
@EinarasGar Thanks for the issue, however this is expected. When you provide --template
, you are telling the command to use that template. When using build
, a template is generated within ./aws-sam/build
which points to all the built artifacts. So the workaround is actually is the right path here.
Leaving open for now in case there are follow ups.
Thank you for a quick reply @jfuss . Apologies for invalid issue. However, I am confused. In what case would supplying template path would be a correct action? Maybe this should be documented better? Thank you
@EinarasGar No need to apologize. We would much rather the community cut an issue than worry about it being "invalid".
In what case would supplying template path would be a correct action? Maybe this should be documented better?
I thought we added something in this area, I know this is a gotcha that has gotten customers before. I will check this deeper to see what we can do here. Suggestions are welcome, either in docs or in the CLI output. Knowing where you would look and where/what you would expect is always helpful info.
On the "when to supply" part: If you name the template in the "auto discoverable" name (template.yaml, template.yml, or template.json), you should never need to supply the template. If you have a custom template name, and use sam build
, only providing -t
to sam build
is all you need. If you aren't using sam build
, then all commands would be needed. I feel there is some case with package
and deploy
but can't specifically recall.
I am going to assign this to myself, as a reminder to come back once I do a deeper dive with the docs. So would just ask to leave this open, until we have clear messaging on these cases.
@jfuss, I looked around a bit more and you are right that there is documentation about it which does state that the --template
parameter is to be used within the build directory. It does make sense.
That being said, it is counter intuitive for a new user learning about the toolkit.
The build command expects a template of a project
The start-api command expects template of build artifacts
I would expect that in case that the user has custom template, the -t
argument shall be used with all commands involving a template. The last thing I would expect is that template path should be where the build directories are.
The sam cli help command also does state that it references build artifacts
AWS SAM template which references built
artifacts for resources in the template. (if
applicable) [default:
template.[yaml|yml|json]]
but again, as for a new user learning about toolkit, I was not aware that build command creates a seperate template and places it in build artifacts folder.
That being said, I think the best course of action would be to check if the build artifacts are located in the same folder as the template.
For instance, if the template expects functions AddTransactionFunctionsDefaultGenerated
, AddTransactionFunctionsAddGenerated
.... , then check if cwd of template contains folders AddTransactionFunctionsDefaultGenerated
, AddTransactionFunctionsAddGenerated
.
If the folders are not found, the start-api
command should print a warning message that there are missing files and state that the provided template should be in the same directory as other build files.
Right now the start-api
command just tries to mount folders based on the current working dir, and if the folders are not there, it still tries to run programs resulting in errors.
So to reiterate, the documentation does say correct things, its just not very intuitive how to use -t
argument for a new user.
Description:
When starting API for nested stack and providing the template file, the API does not work. In this case I am using dotnet AWS template https://github.com/aws/aws-lambda-dotnet/tree/master/Blueprints/BlueprintDefinitions/vs2022/AnnotationsFramework/template/src/BlueprintBaseName.1
Steps to reproduce:
dotnet new serverless.Annotations -n name
Enter the source folder of the functionsam build -t serverless.template
sam local start-api -t serverless.template
Observed result:
The API does not work when performing request to one of the endpoints
Expected result:
The API should work
Workaround
The API DOES work when running commands
sam build -t serverless.template
sam local start-api
(note that in second command template path is not supplied, but everything works as it should)Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
SAM CLI, version 1.53.0 OS: Linux - docker dotnet 6 development container