Bug: sam build generates template.yaml with StateMachine DefinitionUri reference file outside build folder
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description:
When using an `AWS::Serverless::StateMachine` resource with `DefinitionUri` pointing to a local file, `sam build` generates the artifact in the build folder but the `DefinitionUri` points to a file outside the build folder.
I understand the [AWS::Serverless:StateMachine doc](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html#sam-statemachine-definitionuri) does warn about it.
I think the result of `sam build` should not reference anything outside the build folder.
In our use case, we are trying to create a re-usable artifact that would work across regions and we have a StateMachine and some Lambda functions. The artifact generated by `sam package` only allows us to deploy in a single region. Given `sam deploy` executes `sam package` automatically, I think the re-usable artifact should be the one generated by `sam build`.
There was an [issue created](https://github.com/aws/aws-sam-cli/issues/2926) 2 years ago.
### Steps to reproduce:
Given a `template.yml` with a `StateMachine`:
```yaml
MyStateMachine:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: state_machine_definition.json
```
### Observed result:
When I run:
```sh
sam build
```
Then, the generated template looks like this:
```yaml
MyStateMachine:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: ../../state_machine_definition.json
```
> **Note**
The `DefinitionUri` of the StateMachine is pointing to the file outside the build folder.
### Expected result:
In this case, similar to what building a lambda function does, I would expect `sam build` to copy the `state_machine_definition.json` into the `build` folder automatically and make sure the `definitionUri` points to that file in the `build` folder.
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: Amazon Linux
2. `sam --version`: `1.68.0`
3. AWS region: `us-west-2`
```
# Paste the output of `sam --info` here
```
`Add --debug flag to command you are running`
Contributor guide
Assessment
This issue has not been assessed yet.