Deploy Your Serverless Infrastructure

Hmm I’m not sure if you can do that where the entire Serverless project is deployed to one region but one resource in it goes to a different region. The way to get around this would be to define them as separate services. That way each service can go to any region. We talk about this pattern here - https://serverless-stack.com/chapters/organizing-serverless-projects.html

1 Like

Awesome @jayair - this really helped! You solved it! Thanks a lot, appreciated!
Best, Leo

1 Like

did you managed to find solution for this problem

What’s the problem you are having?

@leogonzalez @jayair
For legal reasons, I need to have my data in my country => S3 and DynamoDB cannot be in region us-east-1. Having the Cognito credentials there is alright though.

I’ve tried to separate the Cognito service by moving the resources and creating a Cloud Formation template

my-app/
├── cognito-service/
│   ├── resources/
│   │      ├── cognito-identity-pool.yml
│   │      └── cognito-user-pool.yml
│   └── serverless.yml
├── stuff.js
├── resources/
│       ├── api-gateway-errors.yml
│       ├── dynamodb-table.yml
│       └── s3-bucket.yml
└── serverless.yml

That way I have 2 separate structures: one for API gateway, DynamoDB, S3 (in my region) and one for Cognito (only in us-east-1).

Then, as Cognito has references to the other resources, I needed to cross-reference resources. However Amazon doc states that

You can’t create cross-stack references across regions.

How did you manage to move Cognito to its own region then?

1 Like

So the limitation here is that you can’t have cross stack references across regions. That unfortunately means that you would have to hard code the references?

Does that work for you?

I’m still on the cloud formation learning hill, so I’m not 100% sure of what you mean. I’ll try to explicit my understanding with the S3 cross reference

          - Effect: 'Allow'
            Action:
              - 's3:*'
            Resource:
              - Fn::Join:
                - ''
                -
                  - Fn::GetAtt: [AttachmentsBucket, Arn]
                  - '/private/'
                  - '$'
                  - '{cognito-identity.amazonaws.com:sub}/*'

would be replaced with

          - Effect: 'Allow'
            Action:
              - 's3:*'
            Resource:
              - Fn::Join:
                - ''
                -
                  - 'arn:aws:s3:::MY_BUCKET_NAME'
                  - '/private/'
                  - '$'
                  - '{cognito-identity.amazonaws.com:sub}/*'

However that didn’t work just like that, I still have region issues. Moreover, there’s an issue because S3 are globally named and I can’t hard code a reference to the S3 bucket without knowing its name in advance…

I’m not too familiar with this problem. But by hardcoding I meant that you would have to deploy the S3 service separately, then get the deployed bucket name and use it in the other service.

Yeah doing that in 2 steps works, although it breaks down the flow. Thanks for the advice, got it working like that :slight_smile:

I’m getting same problem, does anyone know the solution?

This is usually related to a YAML formatting issue. Can you compare it to the one in the repo?

thank you, I’ve fixed it

1 Like

I keep getting Inaccessible host issues. I saw a solution on the Serverless forum here:

What do you think about this step?

It’s not my first serverless app I’ve made with this tutorial but this is the first time I’m having these issues.

Thanks for a super tut. Practically jump-started my career

Thanks!

Hmmm are you using a VPC for your application?

Nah,

My configuration is similar to the one in the tutorial

Mayowa Daniel

Sometimes the inaccessible host issue can be just your computer or wifi unable to access the resources. But the issue you posted seems more related to VPC. So I’m not sure what’s going on.

1 Like

I am getting this error while doing Serverless deploy -v

For debugging logs, run again after setting the “SLS_DEBUG=*” environment variable.

Whats the error you are getting?

Hi, I am getting the following error when running the deploy command - any ideas what the issue might be?
(I tried setting the SLS_DEBUG env var but not clear how/where that should be set):

Error: The CloudFormation template is invalid: Invalid template resource property 'CognitoAuthRole'

This is the complete log output:

 ~ serverless deploy -v --aws-profile serverless                                                                                                                                                                                                                                                                             Tue Dec 24 14:41:07 2019
Serverless: DOTENV: Loading environment variables from .env:
Serverless:      - AWS_PROFILE
Serverless:      - STRIPE_SECRET_KEY
Serverless: Using configuration:
{
  "webpackConfig": "node_modules/serverless-bundle/src/webpack.config.js",
  "includeModules": false,
  "packager": "npm",
  "packagerOptions": {},
  "keepOutputDirectory": false
}
Serverless: Removing /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack
Serverless: Using multi-compile (individual packaging)
Serverless: Bundling with Webpack...
Serverless: Zip function: /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack/create [19 ms]
Serverless: Zip function: /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack/get [7 ms]
Serverless: Zip function: /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack/list [7 ms]
Serverless: Zip function: /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack/update [9 ms]
Serverless: Zip function: /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack/delete [7 ms]
Serverless: Zip function: /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack/billing [11 ms]
Serverless: Packaging service...
Serverless: Remove /Users/andersramsay/dev/ar/serverless/notes-app-api/.webpack
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service create.zip file to S3 (82.11 KB)...
Serverless: Uploading service get.zip file to S3 (77.45 KB)...
Serverless: Uploading service list.zip file to S3 (77.49 KB)...
Serverless: Uploading service billing.zip file to S3 (147.12 KB)...
Serverless: Uploading service delete.zip file to S3 (77.29 KB)...
Serverless: Uploading service update.zip file to S3 (77.99 KB)...
Serverless: Validating template...
 
  Error --------------------------------------------------
 
  Error: The CloudFormation template is invalid: Invalid template resource property 'CognitoAuthRole'
      at provider.request.catch.error (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:20:13)
      at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:547:31)
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:604:18)
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:649:10)
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:725:18)
      at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:93:12)
      at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:86:9)
      at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:102:5)
      at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:15:14)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)
      at process.topLevelDomainCallback (domain.js:126:23)
 
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              10.16.0
     Framework Version:         1.60.1
     Plugin Version:            3.2.6
     SDK Version:               2.2.1
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0

Code repo: https://github.com/andersr/notes-api

I did a line by line review of the yml files and found a couple indentation errors. I am now getting the following error:

Error: The CloudFormation template is invalid: [/Outputs/UserPoolId/Value] 'null' values are not allowed in templates . This seems to be pointing to an issue relating to my user pool config but not able to see any issues in that file.