Deploy Your Serverless Infrastructure

Solved the issue by copying and pasting the config files from the demo api so appears to have been yaml formatting issues all along, which to me was not apparent from the error.

These indentation errors are incredibly frustrating. Iā€™m glad you figured it out.

This one definitely had me stumped for a while. I was having the same issue as @kpathakota.

I pulled the RAW copies of the files from the Project repository and did a COMPARE - the spacing issues stood out a lot easier than reading the tutorial. Iā€™m not sure if Iā€™m correct, but I think my IDE (VSCode) was adding spaces in some cases.

NOTE: A comment regarding a misspelling in serverless.yml file >> LINE 14 - fallsback should be > falls back

1 Like

I spent forever on this issue, I was getting this error:

Error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource NotesTable

The root cause was that I had a typo in the filename for the dynamodb-table.yml, I had it as dynaodb-table.yml. Future me knows the joys of manually typing in filenames.

Oh wow thatā€™s annoying. Glad you figured it out.

1 Like

I got stuck trying to deploy my serverless APIs running serverless deploy -v returned the following error:

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

It seems that the variables in resources/cognito-policy.yml are not being passed properly. Anything I should do to fix it?

It might be important to note that I moved the resources directory inside services/notes (even though it is not asked as part of Getting production ready chapter ) to replicate what I could see in the reference code in the github repo. If I leave it at the root of notes-app-api the deployment works but I assume it ignores the resources.

Thank you.

R.

Can you post the part of your serverless.yml thatā€™s causing this error?

Hi @jayair! this is the part of serverless.yml that is causing the error (line 110-111):

  # Cognito Identity Pool Policy
  - ${file(resources/cognito-policy.yml)}

When running serverless deploy -v , it fails to deploy the IAM policy through the CloudFormation template cognito-policy.yml because it canā€™t seem to find the values for variables ${AWS::Region}, ${AWS::AccountId} and ${ApiGatewayRestApi}.

How/when are those variables passed?

Thanks,

I loved this chapter. Now that Iā€™ve deployed a couple of react apps on aws by clicking around cognito and s3, etc. this was fantastic. So, I have my serverless api that works and I deployed my sst cdk and that worked. However, when I plug these cognito, s3 and api variables in my config.js on my react app, I can authentnicate (hurray!) but when I call my post quotes route, I get a 403 error that I am missing the authentication token. I canā€™t figure out why. It is obviously driving me crazyā€¦ See error message below. Any help is greatly appreciated.

Those are built into Serverless Framework. So if this resource is referenced correctly, itā€™ll pick it up.

Hmm so was this API working before?

The API works when tested with serverless invoke local --function ā€¦ CLI command. But they donā€™t work when I hook them up to the config. The cognito user and identity pools are created. The authenticated role IAM JSON looks a bit different than what I have created about 6 times following this tutorial. I am bringing the config file into index.js and pointing them to the cognito ids and URL pathways like I have done before numerous times. I can authenticate which is good. But I canā€™t call the routes via React. That is when I get the 403 despite being able to authenticate.

Iā€™m having this same issue and cannot seem to resolve. Did you manage to resolve this?

I have the cognito cloudformation yml in the resources folder, but when I run the serverless deploy I get the following:
Serverless: Running ā€œserverlessā€ installed locally (in service node_modules)

  Serverless Error ---------------------------------------
 
  Invalid variable reference syntax for variable AWS::Region. You can only reference env vars, options, & files. You can check our docs for more info.
 
  Get Support --------------------------------------------
 Docs:          docs.serverless.com
 Bugs:          github.com/serverless/serverless/issues
 Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
 Operating System:          darwin
 Node Version:              12.18.4
 Framework Version:         2.15.0 (local)
 Plugin Version:            4.2.0
 SDK Version:               2.3.2
 Components Version:        3.4.3

My resources section in the yml looks like:

# Create our resources with separate CloudFormation templates
resources:
  # API Gateway Errors
  - ${file(resources/api-gateway-errors.yml)}
  # Cognito Identity Pool Policy
  - ${file(resources/cognito-policy.yml)}

I seem to have solved this problem with

variableSyntax: ā€œ\${((?!AWS)[ ~:a-zA-Z0-9._@'",\-\/\(\)]+?)}ā€

in my serverless.yml file, which specifies a specific variable syntax allow cloudformation pseudoparameters per this documentation: Serverless Framework Variables

1 Like

In a project where thereā€™s multiple services, would the structure really be set up this way?
Meaning, a separate package.json, serverless.yml, node_modules, etc for every service?
Or would it make more sense to have the package.json, serverless.yml, etc in the higher level services directory so the same packages are used for every service?

The invoke local call doesnā€™t include authentication. So the next step here would be to test it with the CLI in this chapter:

We talk about this in a separate section in the guide:

failed: Export infrastructure-TableName cannot be updated as it is in use by my-app-api-dev

I got pretty far with this guide, but I had to go back and change some things, add a GSI to the dynamodb table, among other things. And I go to deploy and I get this errorā€¦ seems really counter productive, of course things are going to change whats the big deal canā€™t I tell it to just do it or tear down the existing service first or something??