question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variables replacement does not work in nested templates

See original GitHub issue

This is a Bug Report

Description

For bug reports:

  • What went wrong?

Variables replacement did not work in my resources file. This is not a problem in 1.12.1

Using the sls package command the DynamoTable part of the cloudformation-template-update-stack.json is :

"DynamoTable": {
    "Type": "AWS::DynamoDB::Table",
    "Properties": {
      "TableName": "${self:service}-${self:custom.stage}-myAttribute",
      "AttributeDefinitions": [
        {
          "AttributeName": "myAttribute",
          "AttributeType": "S"
        }
      ],
      "KeySchema": [
        {
          "AttributeName": "myAttribute",
          "KeyType": "HASH"
        }
      ],
      "ProvisionedThroughput": {
        "ReadCapacityUnits": 10,
        "WriteCapacityUnits": 10
      }
    }
  }
  • What did you expect should have happened?

The DynamoTable part of cloudformation-template-update-stack.json should be:

    "DynamoTable": {
      "Type": "AWS::DynamoDB::Table",
      "Properties": {
        "TableName": "sls-variables-test-dev-myAttribute",
        "AttributeDefinitions": [
          {
            "AttributeName": "myAttribute",
            "AttributeType": "S"
          }
        ],
        "KeySchema": [
          {
            "AttributeName": "myAttribute",
            "KeyType": "HASH"
          }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": 10,
          "WriteCapacityUnits": 10
        }
      }
    }
  • What was the config you used?

Project Structure

.
├── handler.js
├── serverless.yml
└── slsConfig
    └── aws-resources
        ├── dev.resources.yml
        └── templates
            └── dynamoDB.resources.yml

serverless.yml

service: sls-variables-test

custom:
  stage: ${opt:stage, self:provider.stage}
provider:
  name: aws
  runtime: nodejs6.10
  stage: dev

functions:
  hello:
    handler: handler.hello

resources:
  Resources:
    ${file(slsConfig/aws-resources/${self:custom.stage}.resources.yml)}

slsConfig/aws-resources/dev.resources.yml

${file(slsConfig/aws-resources/templates/dynamoDB.resources.yml)}

slsConfig/aws-resources/templates/dynamoDB.resources.yml

DynamoTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: '${self:service}-${self:custom.stage}-myAttribute'
    AttributeDefinitions:
      - AttributeName: myAttribute
        AttributeType: S
    KeySchema:
      - AttributeName: myAttribute
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 10
      WriteCapacityUnits: 10
  • What stacktrace or error message from your provider did you see?
..........Serverless: Deployment failed!

  Serverless Error ---------------------------------------

     An error occurred while provisioning your stack: DynamoTable
     - 1 validation error detected: Value '${self:service}-${self:custom.stage}-myAttribute'
     at 'tableName' failed to satisfy constraint: Member
     must satisfy regular expression pattern: [a-zA-Z0-9_.-]+.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless

  Your Environment Information -----------------------------
     OS:                 linux
     Node Version:       6.10.2
     Serverless Version: 1.13.0

Similar or dependent issues:

Additional Data

  • Serverless Framework Version you’re using: 1.13.0
  • Operating System: Gnome Ubuntu 16.04
  • Stack Trace:
  • Provider Error messages:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
NaraGitHubcommented, May 31, 2017

Fixed and working - Tested with 1.14.0

0reactions
pmuenscommented, Jun 1, 2017

Thanks for confirming @NaraGitHub 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested variable and resource with copy not working
I have defined "lbApiVersion" inside nested resource variable block but some how the nested variable block is not recognize. below is the ARM ......
Read more >
Variables in templates - Azure Resource Manager
Describes how to define variables in an Azure Resource Manager template (ARM template).
Read more >
Where variables can be used - GitLab Docs
- Variables from pipeline schedules. Not supported are variables defined in the GitLab Runner config.toml , variables defined in jobs, or Persisted variables....
Read more >
The Django template language - Django documentation
The Django template system provides tags which function similarly to some ... If you use a variable that doesn't exist, the template system...
Read more >
macro, nested, return - Apache FreeMarker Manual
The variable will be created at the beginning of the template; it does not mater where the macro directive is placed in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found