Search code examples
amazon-web-servicesamazon-s3amazon-cloudfrontserverless-framework

Change region using npx serverless to deploy on AWS CloudFront


I uploaded to AWS CloudFront my Next JS app, with the following commands:

  1. Creating my Nextjs app:

    npx create-next-app

  2. Create a serverless app with npx serverless using aws-nodejs template:

    npx serverless create --template aws-nodejs

  3. Updated my serveless.yml defining as serveless next component:

    myNextApp:
      component: "@sls-next/[email protected]"
    
  4. Finally deploying my app in CloudFront:

    npx serverless

This work fine! Only a doubt.... my Cloud front distribution has as origin S3 located as default in us-east-1, ¿how can I change the origin S3 region? I need it will be in eu-central-1. Is it possible to change the S3 region on deployment?

enter image description here


Solution

  • I had the same issue. You can't change the server region afterwards. I deleted everything (.serverless and .next-serverless folders that were created) and changed the serverless.yml. Add the following in your serverless.yml file:

    myNextApp:
    
      component: "@sls-next/[email protected]"
    
      inputs:
    
        bucketName: nameforyourbucket
    
        bucketRegion: eu-central-1
    

    And deploy using npx serverless