Code Monkey home page Code Monkey logo

website's Introduction

Serverless Components


Click Here for Version 1.0


Serverless Website Component ⎯⎯⎯ Instantly deploy static website on serverless infrastructure with zero configuration, powered by Serverless Components.


  • Zero Configuration - Just let us know the component name, then just deploy.
  • Fast Deployments - Deploy your entire website or frontend in seconds.
  • CDN, SSL & Custom Domains - Comes with free CDN, SSL & custom domains out of the box.
  • Team Collaboration - Collaborate with your teammates with shared state and outputs.
  • Built-in Monitoring - Monitor your website right from the Serverless Dashboard.

Check out the Serverless Fullstack Application for a ready-to-use boilerplate and overall great example of how to use this Component.


 

Install

To get started with this component, install the latest version of the Serverless Framework:

$ npm install -g serverless

After installation, make sure you connect your AWS account by setting a provider in the org setting page on the Serverless Dashboard.

Initialize

The easiest way to start using the website component is by initializing one of its templates using the init command:

For React:

serverless init react-starter
cd react-starter

For Vue:

serverless init vue-starter
cd vue starter

This will also run npm install for you.

Deploy

Once you have the directory set up, you're now ready to deploy. Just run the following command from within the directory containing the serverless.yml file:

$ serverless deploy

Your first deployment might take a little while, but subsequent deployment would just take few seconds. For more information on what's going on during deployment, you could specify the --debug flag, which would view deployment logs in realtime:

$ serverless deploy --debug

Configure

The Website component is a zero configuration component, meaning that it'll work out of the box with no configuration and sane defaults. With that said, there are still some optional configuration that you can specify.

Here's a complete reference of the serverless.yml file for the website component:

component: website               # (required) name of the component. In that case, it's website.
name: my-website                 # (required) name of your website component instance.
org: serverlessinc               # (optional) serverless dashboard org. default is the first org you created during signup.
app: my-app                      # (optional) serverless dashboard app. default is the same as the name property.
stage: dev                       # (optional) serverless dashboard stage. default is dev.

inputs:
  src: ./src                     # (optional) path to the source folder. default is a hello world html file.
  domain: serverless.com         # (optional) domain name. this could also be a subdomain.
  region: us-east-2              # (optional) aws region to deploy to. default is us-east-1.
  bucketName: my-bucket          # (optional) aws bucket name. default is an auto generated name.
  indexDocument: index.html      # (optional) index document for your website. default is index.html.
  errorDocument: index.html      # (optional) error document for your website. default is index.html.

You could also provide a build hook to run before the source gets uploaded by turning the src input into an object:

inputs:
  src:
    src: ./src          # the input source folder
    hook: npm run build # the hook you want to run
    dist: ./dist        # the output dist folder

Once you've chosen your configuration, run serverless deploy again (or simply just serverless) to deploy your changes.

Dev Mode

Now that you've got your basic website up and running, it's time to develop that into a real world application. Instead of having to run serverless deploy everytime you make changes you wanna test, you could enable dev mode, which allows the CLI to watch for changes in your source directory as you develop, and deploy instantly on save.

To enable dev mode, simply run the following command from within the directory containing the serverless.yml file:

$ serverless dev

Get Info

Anytime you need to know more about your running website instance, you can run the following command to view the most critical info.

$ serverless info

This is especially helpful when you want to know the outputs of your instances so that you can reference them in another instance. It also shows you the status of your instance, when it was last deployed, and how many times it was deployed. You will also see a url where you'll be able to view more info about your instance on the Serverless Dashboard.

To digg even deeper, you can pass the --debug flag to view the state of your component instance in case the deployment failed for any reason.

$ serverless info --debug

Remove

If you wanna tear down your entire website infrastructure that was created during deployment, just run the following command in the directory containing the serverless.yml file.

$ serverless remove

The website component will then use all the data it needs from the built-in state storage system to delete only the relavent cloud resources that it created. Just like deployment, you could also specify a --debug flag for realtime logs from the website component running in the cloud.

$ serverless remove --debug

FAQs

What AWS Resources Does This Component Create?

  • AWS S3 Bucket for hosting
  • AWS CloudFront for CDN

And if you set a domain:

  • AWS ACM Certificate for SSL
  • AWS Route53 for DNS

How to use a custom domain registered outside of AWS?

If your domain is not on AWS Route53, you will have to set this up manually because the component does not have access to your registrar. Here are the general steps involved.

  1. Create an AWS ACM certificate for your domain. Make sure you set the "Additional Names" field to *.yourdomain.com as well to include all subdomains as well.
  2. After you create the certificate, it should be in a PENDING_VALIDATION status. Now you will need to validate your domain. We suggest you follow the DNS steps by adding the validation CNAME record you see on the AWS console to your domain via your registrar dashboard.
  3. After you add the validation record, it might take a while, but eventually the certificate should change status to ISSUED. Usually it takes around 5 minutes.
  4. Add your domain to the serverless.yml file as shown above and deploy. This step is important as it adds your domain to the cloudfront distribution.
  5. Notice the cloudfront url that is returned as an output. Copy this URL, get back to your registrar and add another CNAME record with your domain or subdomain name and a value of this cloudfront url. This ensures that your domain points to that cloudfront URL.
  6. After around 20 mins, your SSL certificate and domain should all be working and pointing to your URL. Keep in mind that if you change the name, stage, app or org properties in serverless.yml, this would result in a completely new instance with a new cloudfront url. This allows you to setup different domains for each stage or instance

website's People

Contributors

ac360 avatar daveoneday avatar durgaprasad-budhwani avatar eahefnawy avatar fodurrr avatar morgler avatar neilime avatar skierkowski avatar spekulatius avatar thepont avatar uxtx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

website's Issues

Ability to add Expires headers

Currently, all the assets come without any max-age headers. This leads to a lower performance score on Google Page Insights.

Any possibility to add those with this component?

Unsupported AWS ACM Certificate status

I keep getting this error:

Error: Your AWS ACM Certificate for the domain "domain.com" has an unsupported status of: "VALIDATION_TIMED_OUT".  Please remove it manually and deploy again.

My serverless.yml is like

name: website

website:
  component: '@serverless/website'
  inputs:
    code:
      src: build
      hook: yarn build
    domain: sub.domain.com
    region: eu-west-1

Maybe is there an issue assigning a subdomain to the website?

Update AWS Bucket Policy

When I deploy using @serverless/website I am unable to override the Bucket Policy for the S3 bucket I am creating.

Instead of it being:

"Principal": {
    "AWS": "*"
}

I would like it to be configurable to achieve:

"Principal": "*"

Is this achievable?
I would say yes since I installed the NPM package locally, and I was able to find the method configureBucketForHosting inside utils.js, the Principal value is hardcoded.

Is there a way for me to create a pull request to @serverless/website?
I am not able to find the open source repo

Using variables in definition

Hey, I'm trying to use variable to declare my domain name, but for some reason I can't seem to get it to work. Here's a simple example that errors

custom:
  domain: example.com

inputs:
  domain: ${self:custom.domain}

Which returns the error:

Error: "${self:custom.domain}" is not a valid domain.

Are variables not available for config?

Thanks

CLI Init Directory Name

Is there a way to change the directory name the template is dropped into? For example, when I type serverless init react-starter, it will always put it in the react-starter directory. If I want to drop the template into the myAwesomeWebsite directory instead, is there a way to modify the init command to do this or do I just have to rename the directory every time?

Sorry if this is answered somewhere else, I dug through the components documentation and there doesn't seem to be any other commands documented with the init command.

Deploy to different AWS accounts

I'm having problems deploying my site to different AWS accounts for staging purposes. I have two AWS accounts, one for DEV and one for PROD. My current approach to deploy to either one is by running sls deploy --stage <stage> --aws-account <account>. Each AWS account stored within .aws/credentials is pointing to the corresponding IAM user with admin access. It seems like the --aws-account flag is being ignored and the bucket is created in the account associated with the provider account linked within the Serverless dashboard.

I also tried adding a provider for each account for my app within the dashboard following https://www.serverless.com/framework/docs/guides/providers/. By doing this I'm able to deploy other components (database, api, permissions) to the right accounts but the website component keeps failing with an Access denied error.

So am I missing something? My goal is ultimately to wire this up to a CI/CD pipeline - what is the correct way to deploy to different AWS accounts/stages?

CI - Error: Failed running "src.hook": "npm run build" due to the following error: Command failed: npm run build

Hi!

I am hitting this error on app.serverless.com (ci/cd deploys):

Error: Failed running "src.hook": "npm run build" due to the following error: Command failed: npm run build

Using Create React App with TypeScript ("react": "^17.0.1" && "typescript": "^4.0.3",):

org: usernameorg
app: app
component: website
name: app
#
stage: ${env:AWS_STAGE}
#
# https://github.com/serverless/components#simplicity
#
inputs:
  name: app-${stage}
  region: ${env:AWS_REGION}
  src:
    src: ./src
    hook: npm run build
    dist: ./build

  "scripts": {
    ...
    "build": "react-scripts build",
    "deploy:development": "export AWS_STAGE='development' && export AWS_REGION='us-west-2' && sls deploy",
    "remove:development": "export AWS_STAGE='development' && export AWS_REGION='us-west-2' && sls remove",
    ...
  },

app.serverless.com (ci/cd deploys) error

Build step: serverless deploy --stage development --region us-west-2 --force --org usernameorg --app app --debug
Initializing...
Action: "deploy" - Stage: "development" - Org: "usernameorg" - App: "app" - Name: "app"
Deploying...
 Error: Failed running "src.hook": "npm run build" due to the following error: Command failed: npm run build
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-20T00_31_11_903Z-debug.log
    at exec (/var/lang/lib/node_modules/serverless/node_modules/@serverless/platform-client/src/instance.js:200:13)
    at ChildProcess.exithandler (child_process.js:301:5)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
6s › Serverless › Failed running "src.hook": "npm run build" due to the following error: Command failed: npm run build
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-20T00_31_11_903Z-debug.log
 
  Documentation: https://github.com/serverless/components 
  Support: https://app.serverless.com/support 
  Slack: https://www.serverless.com/slack/ 
Build step failed: serverless deploy --stage development --region us-west-2 --force --org usernameorg --app app --debug
Deploy failed!
Error: Build step failed: serverless deploy --stage development --region us-west-2 --force --org usernameorg --app app --debug

domain configuration fails on tlds with multiple dots (eg: example.co.nz)

so, this component fails to create ssl certificates if the domain a tld that has . in it. For example: .co.nz

Here is what happens:

serverless.yml as per documentation/example

component: website
name: some-name
stage: dev

inputs:
  domain: subdomain.example.co.nz
  src:
    src: ./src
    hook: npm run build
    dist: ./dist

run: serverless deploy --debug

error:

...
Checking if a certificate for the co.nz domain exists
Certificate for the co.nz domain does not exist. Creating...
Validating the certificate for the co.nz domain.

 TypeError: Cannot read property 'Name' of undefined
    at ensureCertificate (/var/task/utils.js:392:51)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Website.deploy (/var/task/serverless.js:59:37)
    at async Runtime.module.exports [as handler] (/opt/nodejs/node_modules/@serverless/
core/handler.js:273:24)

When i look at my AWS Certificate Manager, it is trying to create a SSL certificate for .co.nz (and *.co.nz) rather than example.co.nz (and *.example.co.nz). In the above scenario, i have example.co.nz on my Route53 Hosted Zones.

I can easily create a certificate manually, is there a way to tell the component to skip ssl certificate creation and simply provide the certificate arn?

Error deploying in ap-southeast-2 region Inaccessible host: `s3-accelerate.amazonaws.com'.

I'm trying to deploy a simple React app in ap-southeast-2 but having trouble accessing the s3 transfer acceleration endpoint.

Additionally, buckets used with Amazon S3 Transfer Acceleration can't have dots (.) in their names according to these docs https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html where by default, my bucket name has period because I am trying to declare a domain.

Is it possible to turn off S3 Transfer Acceleration? Not sure if others are having this issue.

Also

➜ sls deploy --debug   
Initializing...
Action: "deploy" - Stage: "dev" - App: "reactapp-sls-components" - Instance: "reactapp-sls-components"
Deploying...
...
Deploying Website
Configuring bucket for hosting
Uploading Website files
 UnknownEndpoint: Inaccessible host: `s3-accelerate.amazonaws.com'. This service may not be available in the `ap-southeast-2' region.
    at Request.ENOTFOUND_ERROR (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:495:46)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:683:14)
    at ClientRequest.error (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:333:22)
    at ClientRequest.<anonymous> (/var/runtime/node_modules/aws-sdk/lib/http/node.js:96:19)
    at ClientRequest.emit (events.js:311:20)
    at ClientRequest.EventEmitter.emit (domain.js:482:12)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:311:20)

4s › reactapp-sls-components › Inaccessible host: `s3-accelerate.amazonaws.com'. This service may not be available in the `ap-southeast-2' region.

Ability to provide a custom role arn or role resource for deployment

Issue: Getting
AccessDenied: User: arn:aws:sts::XXXXXXXXXXXXXX:assumed-role/XXXXXXXX is not authorized to perform: iam:CreateRole on resource: arn:aws:iam::XXXXXXXXXX:role/<RANDOM_NAME>
while deploying a ui, api and db as some where down the chain the framework is trying to create roles and it is failing.

I think it is ideal to provide an ability for specifying a role name that already exists in the account or provide an ability to create role and use that for deployment.

In certain organizations the role creation might have restriction.
Ex: Allow creation of new roles only if a standard permission boundary is attached to it. or other scenarios wrt to roles...

In those lines custom role creation will always run into issues.. So if an IAM role is provided, on the fly role creation should be skipped and provided role should be attached to the resources.

@eahefnawy @pmuens @medikoo Thoughts ?

Folders are not uploaded/created on S3 correctly.

The folders are not uploaded/not created on S3. The folder names are merged into the filenames as string (flattened), therefore static assets are not displayed on the created website, worst case with create-react-app that application will not even start because static chunk JavaScript files are created in the static folder.

image

When I upload the static folder via the AWS console manually into the same bucket then everything works fine.

Probably the problem is here: websiteBucket.upload.

Btw where can i find this @serverless/aws-s3 package which has the websiteBucket.upload function on github? May be I could do a PR.
Thanks

Unexpected behavior on multi-level subdomains

Trying to deploy a website that would be hosted on a.sub.domain.com, I have a route53 and certificate setup for sub.domain.com but due to company policy cannot have that on domain.com
While deploying it translates the domain naked in util.js resulting to domain.com which fails. It would be better to give a nakedDomain config on serverless.yml. Can you also suggest a way to overcome this problem?

Support for multiple environments

Hello, I am new to the Serverless community. Serverless framework has been awesome for me. I migrated my API(s) successfully completely through Serverless framework tutorial. Now I am migrating my front-end code as well. As I am building my react front-end app using this website component, I stumbled upon how I can configure dev vs prod environment. To be precise, under my /src folder I have appconfig.js file where I have environment variables logic with process.env.NODE_ENV that tells the front-end which endpoint it should go (dev/prod). With Serverless website (Client-side rendering) and static hosting, is there any way I can point my front-end to different API endpoints depending on the stage or some other variables? If not, will this feature be added? Thank you for the help in advance!

Domain redirects to aws generated bucket url?

I have set things up according to the example with my own custom domain. However, the domain 301 redirects to the aws generated bucket url? Where the site is loading fine, but obviously i don't want the redirect. is this intended behaviour?

Allow configurable bucket

The name of the bucket used to store the static files is saved in the .serverless folder, which isn't supposed to be included in source control. Therefore, every time a new version of a website is deployed from a machine that doesn't contain that folder (CD/CI pipeline for instance), the component creates a new bucket where it uploads the website. This isn't ideal in some cases, especially since old buckets aren't automatically removed. Therefore, I believe it would make sense to let people pass the name of a concrete bucket to the component through an input parameter (same as region for instance).

I've got a fork of the component with that change made, and I'd be more than happy to submit a PR if you agree with the proposed solution.

When deploying command adds cloudfront cname

Result from : sls deploy

Updating CloudFront distribution of ID XXXXXXXX.
Adding "xxxxx.com" certificate to CloudFront distribution
Adding domain "www.xxxxx.com" to CloudFront distribution
Adding domain "xxxxx.com" to CloudFront distribution

I dont own the CNAME for www.xxxxx.com so it throws a InvalidViewerCertificate

serverless.yml

component: website
name: landing-page4
stage: dev

inputs:
  domain: 'http://www.xxxxx.com'
  src:
    src: ./src
    hook: npm run build
    dist: ./dist

Why is it adding the www domain? I cant deploy to live as it stands as its forcing this options. Appreciate some help

Incoherent bug happening for nuxt full static websites

Hello everyone !

I encountered an issue that I solved after a long suffering.

The issue

I deployed a nuxt project to AWS by using the website component in the full static nuxt generate mode.
I had incoherent results like if all the pages had only access to the payload that was generated for the "/" page.

I reproduced the issue here : https://d2xk172pvk6ejw.cloudfront.net/

To reproduce the bug :

  • go to the cloudfront distribution
  • go to Secondary page go back to Home page : you can see there are two different messages (an email for the homepage, a message with emojis for secondary)
  • now refresh the browser while being on the Secondary page => you get the email as on the home page.

You can find the code here : https://github.com/oussj/nuxt-full-static-serverless-website-issue

After looking a bit more, I understood that it was linked to this issue : nuxt/nuxt#2506.

I understood it was linked to the fact that the cloudfront distribution is created with the s3 bucket url, and not the s3 website url. As you can see here in the source code

When I went to the AWS console and I manually changed the Origin Domain Name, everything was back to normal.

Suggestion

I suggest to always create the cloudfront distribution with the website url http://website-oecg92n.s3-website-us-east-1.amazonaws.com instead of http://website-oecg92n.s3.us-east-1.amazonaws.com

If this is not okay for some cloudfront reason (I'd be very interested to understand it), I'd suggest to add a boolean optional input static in serverless.yml

If static would be set to true, the cloudfront distribution would be created with the s3 website url and not the s3 bucket url.

I'd be happy to do the pull request!

Improve Return Errors to be Accurate

When switching to a new AWS environment, we kept getting this error:

Error: Forbidden: Invalid credentials or this AWS S3 bucket name may already be taken

Credentials were correct. Bucket wasn't taken. If there is a way to return AWS error codes to the user that would be more than a little useful. Currently, one must recreate an S3 bucket and associate it to a CF CDN via the console to find the actual error: ACM:listCertificates

Extra Credit: Improve documentation to list precise policies needed to run.

TypeError: Cannot read property 'ping' of null

I don't know if this is the right place for this - the error looks like it's in platform-client - but that is a private repo.

I get this intermittent error when I deploy from CI/CD environment:

Build step: serverless deploy --stage dev --region us-east-1 --force --org darbio --app tsz-next --debug
Initializing...
Action: "deploy" - Stage: "dev" - Org: "darbio" - App: "tsz-next" - Name: "frontend"
Deploying...
/var/lang/lib/node_modules/serverless/node_modules/@serverless/platform-client/src/Connection.js:114
            this.connection.ping();
                            ^
TypeError: Cannot read property 'ping' of null
    at Timeout.pingInterval.setInterval [as _onTimeout] (/var/lang/lib/node_modules/serverless/node_modules/@serverless/platform-client/src/Connection.js:114:29)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)
Build step failed: serverless deploy --stage dev --region us-east-1 --force --org darbio --app tsz-next --debug

I think there is a bug in platform-client when the connection times out.

Old build artifacts not removed from s3

Hi there, first off thanks for making such an easy to use framework!

I'm trying out this component for deploying a React SPA with S3 & CloudFront. However I'm noticing that build artifacts from previous builds remain in my bucket - is there an option to remove these on a fresh deploy? (Similar to the default behaviour of serverless-finch)

Best
Zac

Enhancement suggestion: set GZIP compression to true when creating Cloudfront distribution

Hello!

Most of the suggestion is in the title. When I audited with Lighthouse my static website deployed with the serverless website component, I found out that I had a lot to win by gzipping my assets.

Gzipping is not enabled by default when creating the distribution as I could see it here

I suggest to set this value to true by default instead of false

Otherwise, if for some reason the default behaviour should not change, I suggest adding it as an optional input in the serverless.yml file

I'd be happy to do the pull request.

Wrong, partial s3 bucket in cloudfront

On the most recent Serverless version, had this S3 bucket name as an input:

bucketName: welcome-dev.remember.us

The correct s3 bucket is created correctly:

http://welcome-dev.remember.us.s3-website-us-west-2.amazonaws.com

I also mapped a subdomain, and it points to a cloudfront dist that was also created.

The problem is that the cloudfront dist has the origin as welcome-dev.s3.amazonaws.com which is wrong. It's not using the whole bucket name welcome-dev.remember.us.

Wildcard Domains Fail

When trying to set a wildcard domain you get an error saying the domain isn't a valid domain.

ex in yaml:

domain: "*.myapp.com"

result:

41s » Serverless » "*.myapp.com" is not a valid domain.

Incorrect generated website url

From the code the website url is http://${bucketOutputs.name}.s3-website-${inputs.region}.amazonaws.com. Shouldn't it be http://${bucketOutputs.name}.s3-website.${inputs.region}.amazonaws.com? ('.' instead of '-')

Passing variables to static files in different stages?

What's the best way to change api key or api domain uri based on a different stage in a single page application?

If this were a lambda, I would use environment variables in the serverless yml file, but since these are static files I'm not sure the best way to do this.

Rate exceeded error

In the company I work for we are deploying two websites using this component (configured for CloudFront) at the same time. In some occasions, we get a Rate exceeded error, which breaks the deployment, and we can't really tell by the logs where it is coming from.

This is a screenshot of the error:
Screenshot 2019-11-19 at 12 24 53

Do you have any idea what could be the cause of the issue? I've digged into the code and I can't really tell what AWS could be returning the error...

Create Artifacts

HI,

I'm working with this serverless component, so I'm trying to create an artifact with this command

serverless package --package .artifact

but I'm receiving several issues and it seems it doesn't work.

any chance to support that?

Serverless components website : Deploy failed with delegated domain

Hi,
I have two AWS accounts a master account for production and a sub account for Development. In production the deployment works fine, but when I try to deploy in the development account it fails with the following error:

Serverless › [RRSet with DNS name _3638471d4d0b2191ad3718504521cbe6.mydomain.com. is not permitted in zone dev.mydomain.com.]

Screenshot_20201013_235639

In my main account (prod): the domain is like that : backoffice.mydomain.com (works fine) <---- subdomain of "mydomain.com"
in my sub account (dev): it's like that : backoffice.dev.mydomain.com (failed) <---- subdomain of "dev.mydomain.com"

For more detail, In my sub account I have only one hosted zone "dev.mydomain.com" , I have delegated this domain to sub account from the master account.

serverless.yml
Screenshot_20201013_235557

Add support for cli options?

Hey,

I'm playing around this component, and it seems to be working great 👍 .

One thing I cannot get my head around is different environments if I hook this up to some kind of CI process.

For example, if I wanted to support dev, staging, and production

How would you go about doing this?

My thought was to change the bucket name that the code gets pushed too, but it looks like I cannot do this with cli options like I could in the standard serverless.yml setup?

s3 bucket no longer made public by deploy

My vue-starter project no longer gives public read access to the access bucket when it's deployed, I have to manually make everything in the bucket public after every deploy.

Here are the steps I took to get into this state.

  1. Create a new project from the vue-starter template
  2. Run "sls" from the command line to deploy the website
  3. Open the serverless.yml and add a bucketName and domain that match.
  4. Change the app: vue-starter and the name: vue-starter to a new value
  5. Run "sls" again. Observe error that the bucket already exists for a different app and you should remove it first and redeploy.
  6. Stash the changes to the yml, and run "sls remove"
  7. Unstash your changes again and run "sls"
  8. Log into s3 and Observe that all the files in the bucket no longer have Read permissions for the Everyone group.
  9. Manually use the "Make Public" action in s3 to make everything available to the public.
  10. Run "sls" again to redeploy
  11. Refresh your website and see the 403 errors again, confirming in s3 that the files are no longer public again.

www -> root domain redirect Cloudfront clash

Following the tutorial for a www -> root domain redirect (e.g www.example.com -> example.com) https://serverless-stack.com/chapters/setup-www-domain-redirect.html, it directs you to set up a new cloudfront distribution for the www subdomain.

This means the www subdomain can no longer be an alternate domain name (CNAME) record for this cloudfront distribution or this error occurs on deploy:

Error: The domain "www.example.com" is already in use by another website or CloudFront Distribution.
    at updateCloudFrontDistribution (/var/task/utils.js:688:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

This is caused by

website/src/utils.js

Lines 103 to 104 in 6f87650

if (config.domain && config.domain === config.nakedDomain) {
config.domain = `www.${config.domain}`
automatically adding the www alternate domain name (CNAME) record when it is not wanted in this case.

I suggest an option should be added to not include this www alternate domain name (CNAME) for the cloudfront distribution as it makes this style of www redirect impossible.

Serverless.yml env attribute

I've read the documents and it showed to me and attribute called env. Where are the env.js file after serverless deploy?

I'm using component: website vue-starter

Uploading just the static folder

Hi I have a static website project with a folder structure as follows:

Gruntfile.js		compiled/		package-lock.json	serverless.yml		yarn.lock
README.md		metadata.json		package.json		src/

I just want to upload the compiled/ files to my website/bucket but it uploads everything including the node_modules.

Here is my serverless.yml file:

website:
  component: "@serverless/website"
  inputs:
    src:
      src: ./src          # the input source folder
      hook: yarn && yarn build # the hook you want to run
      dist: ./compiled        # the output dist folder
    bucketName: ${cdn.bucketName}
    # domain: www.example.com

cdn:
  component: "@serverless/cdn"

Allow origin configuration on cloudfront

Hi,
It would be awesome to allow origin configuration for the cloudfront distribution. It is a common use case when you want to place your API under xxxxxx.yy/api. That way you could use the output from deploying an API (i.e. through express component).

Right now, in serverless service I am able to do this through this cloudformation configuration:

            DomainName:
              Fn::Join:
                - ''
                - 
                  - Ref: ApiGatewayRestApi
                  - '.execute-api.${self:provider.region}.amazonaws.com'
            OriginPath: '/${opt:stage}'

Wrong origin of CloudFront distribution

I have tried to create my serverless blog with custom domain sls-blog.myowndomain.xyz

    []
    bucketName: 'sls-blog.myowndomain.xyz' 
    domain: sls-blog.myowndomain.xyz
    []

But it ends up with the error as below when I access my own domain

<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName>sls-blog</BucketName>

When I navigate to the Cloudfront Console, I recognize that the CloudFront distribution is trying access the origin as sls-blog.s3.amazonaws.com. Which I really have no chance to own it.

I tried to change the origin to the s3 bucket website domain and It seems to be working now.

Is Serverless components mistaking on create cloudfront distribution ?
I have check the code and find nothing seem to be wrong.

sls deploy gives authentication error

Hello sls!

I have been working with sls to deploy api's for the last few weeks without many problems.

Today I decided to start looking at serverless front-end, i found the serverless learn front end tutorial and it seems out of date. The components no longer exist, so I came to this github.

I tried following the instructions here in the README, and it still fails when trying to serverless deploy.

I tried creating a brand new empty project and running...

serverless init vue-starter
(this finishes fine)

cd vue-starter

serverless deploy
Error: {"errorMessage":"Authentication failed. - Please contact support and provide this identifier to reference this issue - ZVQH6BXLX8QJ"}

I tried using the same access key and secret that works for my api deploys and that didn't work, I also tried creating a new set of keys for the user (which already has admin permissions) and tried those, but it seems no matter what i do, it doesn't seem to work with them in the .env file, and it also isn't using the keys that are in the ~/.aws/credentials file

bucketName property is not honored, not working

Given the following website serverless.yml the bucket is named a random system assigned GUID name regardless of if the bucketName property is there or not.
`
name: my.domain.com
stage: local

website:
component: '@serverless/website'
inputs:
code:
src: client/dist
hook: domain=my.domain.com npm run clean:build
region: us-east-1
bucketName: local.my.domain.com-specialbucketname123
env:
API_URL: https://my.domain.com
STAGE: local

domain: my.domain.com

`
Tried:

  • With/without quotes
  • deleting and re-creating buckets via S3 console
  • bucket with desired name was able to be created via console as well.

Does Not Support Profiles

The .env file is non-standard and requires scripting to switch out or tokenize the .env for different AWS environments. Please update to support 'profile' in yml that references ~/.aws/credentials entries

Deploying does not upload anything to created S3 bucket.

I've set up a Vue project and have the template set up according to the example. It creates a public bucket but does not upload anything to the bucket. I have the code root folder pointed to the base directory and the src directory pointed to the dist folder that is created after "npm run build".

Ability to override IndexDocument and ErrorDocument

for a project I'm working on we discovered it'd be desirable to override the indexDocument and errorDocument - and would be great to be able to specify the desired override in the serverless.yml/serverless.js configuration, eg, something like:

# serverless.yml

name: my-website
stage: dev

myWebsite:
  component: "@serverless/website"
  inputs:
    code:
      root: ./ # The root folder of your website project.  Defaults to current working directory
      src: ./src # The folder to be uploaded containing your built artifact
      hook: npm run build # A hook to build/test/do anything to your code before uploading
    region: us-east-1 # The AWS region to deploy your website into
    bucketName: myBucket # (Optional) The Bucket name where `src` files/folder will be upload. 
                         # If not provided, it will create random bucket name and upload `src` files
    env: # Environment variables to include in a 'env.js' file with your uploaded code.
      API_URL: https://api.com

    ### NEW PROPERTIES HERE
    indexDocument: index.html # (Optional) the default page for your website
    errorDocument: index.html # (Optional) the error page for your website.
    ### END NEW PROPERTIES


    # You can specify a custom domain name for your website.
    # You must have a public hosted zone available for this domain in AWS Route53.
    # This is done automatically for you if you've purchased the domain via AWS Route53.
    domain: www.example.com

Any chance I could submit a patch to this project to enable this functionality?

fails depending on domain name

When my config contains a domain entry with a dash:

domain: www-test.mydomainname.com

the deploy fails with

InvalidChangeBatch: [The request contains an invalid set of changes for a resource record set 'A www-test.mydomainname.com.']

but when the config has no dash

domain: test.mydomainname.com

it works fine.

Duplicate plugin/preset detected.

After installing and trying to run npm run build I got the error:
Duplicate plugin/preset detected.

I was able to resolve this by removing the plugins section from package.json

since the preset nano-react-app already includes those plugins, they don't need to be declared again in package.json heres a related stackoverflow explaining

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.