Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Fn::Sub or Fn::Join not working for SAR template #32

Open
@gallor

Description

@gallor

Description:

Don't know if this is a CloudFormation bug or a SAM bug but since the error appears to be coming from the SAM CLI stack I'm making it here.
I'm unable to utilize CloudFormation functions for parameters in my template under the AWS::ServerlessRepo::Application Metadata section to deploy my application to the Serverless Application Repo (SAR).

Steps to reproduce the issue:
Here's my template.yaml

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: Lambda layer to house all shared code with backend apps
Parameters:
  DeploymentEnvironment:
    Type: String
    Default: dev

Resources:
  NodeModulesLayer:
    Type: AWS::Serverless::LayerVersion
    Properties:
      LayerName: !Sub 'serverless-shared-node-modules-${DeploymentEnvironment}-grant'
      ContentUri: ./
      CompatibleRuntimes:
        - nodejs8.10
        - nodejs10.x
      # could specify Delete if we want to clean up layers?
      RetentionPolicy: Retain

Outputs:
  LayerVersion:
    Description: Node Modules Layer ARN Reference
    Value: !Ref NodeModulesLayer

Metadata:
  AWS::ServerlessRepo::Application:
    Name: !Sub serverless-shared-node-modules-${DeploymentEnvironment}-grant
    Description: >
      Lambda layer to house all Node-based shared code with backend/serverless apps
    Author: grant
    SemanticVersion: 1.0.0
    ReadmeUrl: README.md
    SourceCodeUrl: <url>
  1. I created an s3 bucket named lambda-layers-dev
  2. Run the following commands from the terminal:
    sam package --template-file template.yaml --s3-bucket lambda-layers-dev --output-template-file packaged.yaml
    sam publish --template packaged.yaml

Observed result:
I get the following errors stack trace:

Uploading to d533bb334dcca7b4904d6e56c7e319a3  107675 / 107675.0  (100.00%)
Successfully packaged artifacts and wrote output template to file packaged.yaml.
Execute the following command to deploy the packaged template
aws cloudformation deploy --template-file <path>lambda-layers/packaged.yaml --stack-name <YOUR STACK NAME>
$ sam publish --template packaged.yaml
2019-10-25 10:24:56 Found credentials in shared credentials file: ~/.aws/credentials
Traceback (most recent call last):
  File "/usr/local/bin/sam", line 11, in <module>
    load_entry_point('aws-sam-cli==0.23.0', 'console_scripts', 'sam')()
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 93, in wrapped
    raise exception  # pylint: disable=raising-bad-type
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/samcli/lib/telemetry/metrics.py", line 62, in wrapped
    return_value = func(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/samcli/commands/publish/command.py", line 52, in cli
    do_cli(ctx, template, semantic_version)  # pragma: no cover
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/samcli/commands/publish/command.py", line 75, in do_cli
    publish_output = publish_application(template_data)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/serverlessrepo/publish.py", line 45, in publish_application
    response = sar_client.create_application(**request)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/botocore/client.py", line 634, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/botocore/client.py", line 682, in _convert_to_request_dict
    api_params, operation_model)
  File "/usr/local/Cellar/aws-sam-cli/0.23.0/libexec/lib/python3.7/site-packages/botocore/validate.py", line 297, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Name, value: OrderedDict([('Fn::Sub', 'serverless-shared-node-modules-${DeploymentEnvironment}-ga892')]), type: <class 'collections.OrderedDict'>, valid types: <class 'str'>
  1. I've tried Fn::Sub:, Fn::Join: and !Sub. All throw the same error.

Expected result:
When I change in my template the Name property under the ServerlessRep to just a string with no CF functions the layer publishes fine.

I referenced this page for the params for that section:
https://docs.aws.amazon.com/en_pv/serverless-application-model/latest/developerguide/serverless-sam-template-publishing-applications-metadata-properties.html

Sorry if this is me not understanding/finding some of the documentation and if so let me know what I missed. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions