Skip to content
This repository has been 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 opened this issue Oct 25, 2019 · 4 comments
Open

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

gallor opened this issue Oct 25, 2019 · 4 comments

Comments

@gallor
Copy link

gallor commented Oct 25, 2019

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!

@ShreyaGangishetty
Copy link

@gallor Thanks for reporting this issue. Just to make sure you meant AWS::Serverless::Application and not AWS::Serverlessrepo::Application in your template right?

@gallor
Copy link
Author

gallor commented Nov 1, 2019

@ShreyaGangishetty Do you mean under the Metadata section? I followed this AWS doc to set it up and it had ServerlessRepo as the type (although I did find it odd that I couldn't find any documentation to the Metadata section outside of this page) : https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-publishing-applications.html
Is there rather a typo from this doc and I can use a different type?

@ShreyaGangishetty
Copy link

@gallor apologies for the confusion, you need to have AWS::ServerlessRepo::Application in the metadata section and the docs are correct. I was able to deploy your template successfully using sam deploy. But sam publish throws the same error as you mentioned. Intrinsic functions are not supported for sam publish in Metadata section. Transferring this issue to sam cli for documenting/fixing the issue

@ShreyaGangishetty ShreyaGangishetty transferred this issue from aws/serverless-application-model Nov 5, 2019
@ShreyaGangishetty ShreyaGangishetty transferred this issue from aws/aws-sam-cli Nov 5, 2019
@gallor
Copy link
Author

gallor commented Nov 6, 2019

@ShreyaGangishetty Great, thanks so much. Hopefully they'll add support for that. Sorry for the noob question too but how do I look up that issue on aws-sam-cli? I looked at the issue list and this is not showing up (and the activity log looks like you transferred this issue from this repo, then from aws-sam-cli again? Looks like it didn't get transferred). Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants