SangminKim
SangminKim

Reputation: 9166

Seems to conflict between Serverless syntax and CloudFormation syntax

The below is the part of CloudForamtion file loaded by Serverless.

# resource.yml
.
.
.
{"Fn::Sub": "arn:aws:sqs:*:${AWS::AccountId}:sqs-spoon-*-${env:SERVICE}"}

# serverless.yml
.
.
resources:
  - ${file:resource.yml}

${AWS::AccountId} is CloudFormation Pseudo Parameter and ${env:SERVICE} is Serverless variable.

When I run sls deploy, it returns the error.

  Invalid variable reference syntax for variable AWS::AccountId. You can only reference env vars, options, & files. You can check our docs for more info.

It seems to say that Serverless recognize ${AWS::AccountId} as Serverless variable, not as CloudFormation Pseudo Parameter.

Right?

If so, how to have Serverless not to parse Pseudo Parameter so that it will be parsed by CloudFormation later?

Upvotes: 0

Views: 733

Answers (2)

Jared Short
Jared Short

Reputation: 150

You can accomplish support for the native AWS syntax with a single config line in serverless.yml to define the variableSyntax. Details can be found here https://github.com/serverless/serverless/pull/3694.

provider:
  name: aws
  runtime: nodejs8.10
  variableSyntax: "\${((env|self|opt|file|cf|s3)[:\(][ :a-zA-Z0-9._,\-\/\(\)]*?)}"

Upvotes: 0

SangminKim
SangminKim

Reputation: 9166

I can solve it with the plugin.

With the plugin, It cloud be solved by replacing ${AWS::AccountId} with #{AWS::AccountId}.

{"Fn::Sub": "arn:aws:sqs:*:#{AWS::AccountId}:sqs-spoon-*-${env:SERVICE}"}

Upvotes: 1

Related Questions