aws / aws/aws-sam-cli

`!Ref` to local path not supported for `AWS::Serverless::LayerVersion`

Open
#4,767 1 comment 2 reactions 0 assignees View on GitHub
area/intrinsics
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:

See https://github.com/aws/serverless-application-model/issues/2533#issuecomment-1436992090 and linked issues for context.

Given the following template where `CodePath` is a local path:

```yaml
Transform: AWS::Serverless-2016-10-31
Parameters:
CodePath:
Type: String
Resources:
MyLayerVersion:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: !Ref CodePath
```

Deployment fails:

> Resource with id [MyLayerVersion0a209abe4f] is invalid. 'ContentUri' requires Bucket and Key properties to be specified.

### Steps to reproduce:

```
sam init --name sam-app --runtime python3.8 --dependency-manager pip --app-template hello-world
cd sam-app
```

Replace `template.yaml` with:

```yaml
Transform: AWS::Serverless-2016-10-31
Parameters:
CodePath:
Type: String
Resources:
MyLayerVersion:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: !Ref CodePath
```

Deploy:

```
sam build --parameter-overrides CodePath=hello_world/
sam deploy --guided --parameter-overrides CodePath=hello_world/
```

### Observed result:

The template passed to the SAM transform is the following (i.e. doesn't include the packaged assets):

```yaml
Transform: AWS::Serverless-2016-10-31
Parameters:
CodePath:
Type: String
Resources:
MyLayerVersion:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri:
Ref: CodePath
Metadata:
SamResourceId: MyLayerVersion
```

However, with `CodeUri` in `AWS::Serverless::Function`, the following template is deployable and the assets are packaged as expected:

```yaml
Transform: AWS::Serverless-2016-10-31
Parameters:
CodePath:
Type: String
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: !Ref CodePath
Handler: app.lambda_handler
Runtime: python3.9
```

### Expected result:

Expected `!Ref` to work with local paths, similar to `CodeUri`.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: macOS
2. `sam --version`: `SAM CLI, version 1.72.0`
3. AWS region: `us-west-2`

```json
{
"version": "1.72.0",
"system": {
"python": "3.8.16",
"os": "macOS-13.2.1-x86_64-i386-64bit"
},
"additional_dependencies": {
"docker_engine": "Not available",
"aws_cdk": "1.101.0 (build 149f0fc)",
"terraform": "1.3.7"
}
}
```

`Add --debug flag to command you are running`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.