cloudsite

1.0.0-beta.5 • Public • Published

Cloudsite

Low cost, high performance cloud based website hosting manager. Cloudsite features CDN integration, DoS protection, free SSL certificates, and contact forms. In addition, since Cloudsite use "pay as you go" cloud infrastructure, hosting costs are generally well below typical market rates.

If you appreciate this project, you can support us on Patreon @liquidlabs. We also provide support on our discord channel.

Installation

CLI installation

npm i -g cloudsite

Library installation

npm i --omit peer cloudsite

All the peer dependencies are specific to the CLI, so if you're not using the CLI, you can omit them.

Usage

CLI usage

# authenticate with AWS; see below for options
aws sso login --profile your-sso-profile 

cloudsite configuration initialize # walks you through setup questions
# deploys a robust, high performance static site in the cloud
cloudsite create your-domain.com --source-path . # see 'Plugins' for additional options
cloudsite update your-domain.com # updates site content
cloudsite destroy your-domain.com # destroys site infrastructure

See Command reference for all the CLI commands.

Library usage

import { create } from 'cloudsite'

const siteInfo = {
  "apexDomain": "your-website-domain.com",
  "sourceType": "docusaurus", // or 'vanilla'
  "sourcePath": "/Users/your-home-dir/path/to/website/source"
  "plugins": {
    "contactHandler": {
      "settings": {
        "path": "/contact-handler",
        "emailFrom": "contactform@your-website-domain.com"
      }
    }
  }
}

create({ siteInfo }) // siteInfo gets updated with additional info as the site is created

console.log('Final site info:\n' + JSON.stringify(siteInfo))
// you'll probably want to save 'siteInfo' somewhere for future operations on the same site

AWS authentication

Cloudsite works by setting up AWS infrastructure within your own AWS account. We set up authentication in two steps. First, we use API access keys to quickly set up access and then we use the tool to set up a dedicated account with limited authorizations using the recommended single sign-on (SSO) method.

Create your AWS root account

If you don't already have one, the first step is to create your AWS root account.

  1. If you are working on behalf of an organization and have the ability to create email aliases, we suggest you first create 'awsroot@your-domain.com' and use that to sign up.
  2. Navigate to aws.amazon.com.
  3. Click 'Create an AWS Account' or 'Create a Free Account'.
  4. Fill out the required information.

Set up access keys

The access keys will allow the tool to operate under your root (or super-admin) account in order to set up SSO operation. At the end of it all, the tool can delete the access keys for you.

  1. Follow the instructions to Install or update to the latest version of the AWS CLI.
  2. Log into your root account (or super-admin account if you have one).
  3. Click on the account name in the upper right-hand corner and select 'Security credentials'.
  4. Under the 'Access keys' section, select 'Create access key'. You may get a warning; if you do, acknowledge and click next.
  5. Execute:
    aws configure
    And copy+paste the access key ID and secret as prompted.

You can test the access keys by executing:

aws iam get-account-summary

Set up SSO authentication

Now, with keys in place, we can hand the action over to the tool to set up the more secure SSO based authentication.

  1. Execute:
    cloudsite configuration setup-sso --user-email your-email@foo.com --defaults
    If you want to tinker around with what enerything is named, just leave off the --defaults and you will enter an interactive QnA.
  2. Once the above command completes, go back to the AWS console (as the root or a super-admin user) and select the IAM service.
  3. Find the newly created user under 'Users' and select 'Send verification email'.
  4. Finally, to create local credentials the cloudsite tool can use, execute:
    aws sso login --profile cloudsite-manager
    
    Note: if you changed the name of the SSO profile, use that name. 'cloudsite-manager' is the default profile name.

You're now ready to use the tool! From the CLI:

cloudsite create your-domain.com --source-path /path/to/website/files

Integrating with an existing SSO instance

This section is for users that already have a single sign-on instance. If you're starting fresh, refer to the previous sections. You can still use the tool to set up the specific permission set and then create or tie in with an existing user and group.

  1. Execute the base command without the --defaults option:
    cloudsite configuration setup-sso --user-email your-email@foo.com
  2. When asked about the group, you can name an existing group and the tool will tie the cloudsite permissions set to that group.
  3. When asked about the user name, you can name an existing user and the tool will add that user to the previously specified group.

You can also create a new group and user in your existing identity store instance.

Plugins

Cloudsite uses a simple plugin system and at the moment, it's more like "optional features" than full plugins, but it'll get there. There are currently two plugins supported: contact form and CloudFront logging.

Contact form

Supports a single contact with set fields. User defined fields will be supported in a future version.. Currently, the supported fields are:

  • given_name,
  • family_name,
  • email,
  • topics, and
  • message.

When submitted, the form data will be saved in a DynamoDB table and the information will be optionally mailed to a user defined email address. The form processing routine supports both base64 form encoded data and a JSON body.

Configuration options

  • contactHandler.emailFrom (string): The SES verified email to use when sending a submission notification email.
  • contactHandler.emailTo (string): The optional target email. If not provided, emailFrom will be used for both the sender and target.
  • contactHandler.path (string): The absolute URL path (beginning with /) where the form submission handler is called. Use this path in the form action, or JS fetch call and the POST method.

Usage

  1. Set up the form on your website. Set the submit handler to whatever you like (we use '/contact-handler'). We will provide at least one template site for this soon. Until then, if you want immediate support, hit us up on discord.
  2. Activate AWS Simple Email Service (SES).
    • Sign in to the AWS Management Console and open the Amazon SES console at https://console.aws.amazon.com/ses/.
    • Make sure you're setting up SES in the same region as your site. This will be us-east-1 unless you specified a different --region option when you create/created the site.
    • Select 'Get started' (or 'Get set up' maybe) from the SES console home page and the wizard will walk you through the steps of setting up your SES account.
  3. It is recommended that you not use your personal email directly and instead create an alias your account. Then use the alias as the destination account.
  4. To create a site infrastructure with contact form support, you must at a minimum define contactHandler.emailFrom and contacteHandler.path. This can be done during site creation like so (can be combined with other options):
    cloudsite create your-domain.com --source-path . \
      --option contactHandler.path:/contact-handler \
      --option contactHandler.emailFrom:contactform@your-domain.com
  5. Include the optional contactHandler.emailTo setting if you want to send the email to a different address than the "from" email.

See also Updating your site.

CloudFront logging

Enables logging of CloudFront events to an S3 bucket. The infrastructure will create a common logging bucket to receive the logs. Currently, the bucket name is hard coded and will be something like 'your-domain-com-common-logs'.

Configuration options

  • cloudfrontLogs.includeCookies (boolean): Indicates whether to include cookie data in the logs.

Usage

To create infrastructure that includes CloudFront event logs, use the following command (can be combined with other options):

cloudsite create your-domain.com --source-path . \
  --option cloudfrontLogs.includeCookies:true # or false

Setting the option, to either 'true' or 'false' is what enables the CloudFront logs.

See also Updating your site

Updating your site

You can update your site, to add, remove, or reconfigure plugins/options with the 'pluggin-settings' command. For instance, to activate contact form support, you could execute:

cloudite plugin-settings your-domain.com \
  --option contactHandler.path:/contact-handler \
  --option contactHandler.emailFrom:contactform@your-domain.com

and then run:

cloudsite update your-domain.com

Command reference

Usage

cloudsite <options> <command>

Main options

Option Description
<command> (main argument,optional) The command to run or a sub-command group.
--format Sets the format for the output. May be 'terminal' (default), 'text', 'json', or 'yaml'.
--help, -? Prints general or command specific help.
--no-color Disables terminal colorization.
--no-reminders, -R Suppresses any reminders. Particularly useful for programmatic usage where the extra output might break things.
--quiet, -q Makes informational output less chatty.
--sso-profile The AWS local SSO profile to use for authentication.
--throw-error In the case of an exception, the default is to print the message. When --throw-error is set, the exception is left uncaught.
--verbose Activates verbose (non-quiet mode) even in situations where quiet would normally be implied.

Commands

  • cleanup: Attempts to fully delete partially deleted sites in the 'needs to be cleaned up' state.
  • configuration: Command group for managing the cloudsite CLI configuration.
  • create: Creates a new website, setting up infrastructure and copying content.
  • destroy: Destroys the named site.
  • detail: Prints details for the indicated site.
  • document: Generates self-documentation in Markdown format.
  • get-iam-policy: Prints an IAM policy suitable for operating cloudsite.
  • import: Generates a site database based on currently deployed site stacks.
  • list: Lists the sites registered in the local database.
  • plugin-settings: Command group for managing plugin settings.
  • reminders: Command group for managing reminders.
  • update: Updates a website content and/or infrastructure.
  • verify: Verifies the site is up and running and that the stack and content are up-to-date.

cleanup

cloudsite cleanup <options> <apex-domain>

Attempts to fully delete partially deleted sites in the 'needs to be cleaned up' state.

cleanup options
Option Description
<apex-domain> (main argument,optional) Specifies the site to clean up rather than trying to cleanup all pending sites.
--list Lists the sites in need of cleaning up.

configuration

cloudsite configuration [subcommand]

Command group for managing the cloudsite CLI configuration.

configuration options
Option Description
[subcommand] (main argument,required) The configuration action to perform.
Subcommands
  • setup-local: Runs the local setup wizard and updates all options.
  • setup-sso: Runs the SSO wizard and sets up the SSO user authentication in the IAM Identity Center.
  • show: Displays the current configuration.

setup-local

cloudsite configuration setup-local

Runs the local setup wizard and updates all options. This should be used after the SSO account has been created (see 'cloudsite configuration setup-sso').

setup-sso

cloudsite configuration setup-sso <options>

Runs the SSO wizard and sets up the SSO user authentication in the IAM Identity Center.

setup-sso options

Option Description
--defaults Use the defaults were possible and skip unnecessary interactive setup.
--delete Confirms deletion of the Access keys after setting up the SSO access. If neither '--delete' nor '--no-delete' are set, then deletion will be interactively confirmed.
--group-name The name of the group to create or reference. This group will be associated with the permission set and user.
--instance-name The name to assign to the newly created identity center, if needed.
--instance-region The region in which to set up the identity center if no identity center currently set up. Defaults to 'us-east-1'.
--no-delete Retains the Access keys after setting up SSO access.
--policy-name The name of the policy and permission set to create or reference.
--sso-profile The name of the local SSO profile to create.
--user-email The primary email to associate with the user.
--user-family-name The family name of the cloudsite management user.
--user-given-name The given name of the cloudsite management user.
--user-name The name of the user account to create or reference.

show

cloudsite configuration show

Displays the current configuration.

create

cloudsite create <options> <apex-domain>

Creates a new website, setting up infrastructure and copying content.

The first time you launch a new domain, Cloudsite will create an SSL certificate for the domain as necessary. If a new SSL certificate is created, the creation process will exit and you'll be given instructions on how to verify the SSL certificate. Once verification is complete, re-run the create command.

You can use --no-interactive to guarantee headless operation, though you must be sure to specify all primary options. Any un-specified --option for an active plugin will take its default value and any required without a default value will raise an error. See --option and --no-interactive documentation and/or the plugins overview guide for further details.

create options
Option Description
<apex-domain> (main argument,optional) The site apex domain.
--no-build Supresses the default behavior of building before uploading the site content.
--no-delete-on-failure When true, does not delete the site stack after setup failure.
--no-interactive Suppresses activation of the interactive setup where it would otherwise be activated. Any options for activated plugins not set on the command line by an --option will take their default value.
--option A combined name-value pair of plugin options in the form of: <name>:<value>. Can be used multiple times. Setting any option activates the associated plugin and any unset options are queried unless --no-interactive is also set, in which case the options take their default value.
--region The region where to create the site resources. Defaults to 'us-east-1'.
--site-bucket-name The name of the bucket where website content is stored. If no option is given, Cloudsite will generate a random bucket name.
--source-path Local path to the static site root.
--source-type May be either 'vanilla' or 'docusaurus', otherwise process will attempt to guess.
--stack-name Specify the name of the stack to be created and override the default name.

destroy

cloudsite destroy <options> [apex-domain]

Destroys the named site. I.e., deletes all cloud resources associated with the site.

destroy options
Option Description
[apex-domain] (main argument,required) The domain of the site to delete.
--confirmed Skips the interactive confirmation and destroys the resources without further confirmation.

detail

cloudsite detail [apex-domain]

Prints details for the indicated site.

detail options
Option Description
[apex-domain] (main argument,required) The domain of the site to detail.

document

cloudsite document <options>

Generates self-documentation in Markdown format.

document options
Option Description
--section-depth An integer indicating initial header 'depth', where '1' means start with an 'H1/#' section header, '2' means start with an 'H2/##' section header, etc. This is useful when the documentation is embedded in other docs.
--title The title of the top level section header.

get-iam-policy

cloudsite get-iam-policy <options>

Prints an IAM policy suitable for operating cloudsite.

get-iam-policy options
Option Description
--with-instructions When set, will print instructions for creating the policy along with the policy.

import

cloudsite import <options> [domain-and-stack]

Generates a site database based on currently deployed site stacks.

import options
Option Description
[domain-and-stack] (main argument,required) The domain and stack are specified as positional parameters, in either order.
--common-logs-bucket Specifies the common logs bucket name. This is only necessary if there are multiple candidates, otherwise cloudsite can usually guess. Set to 'NONE' to suppress guessing and assume there is on common logs bucket.
--refresh By defaualt, cloudsite will refuse to overwrite existing site DB entries. if '--refresh' is true, then it will update/refresh the existing entry.
--region Specifies the region where the stack is to be found.
--source-path Local path to the static site root.
--source-type May be either 'vanilla' or 'docusaurus', otherwise process will attempt to guess.

list

cloudsite list <options>

Lists the sites registered in the local database.

list options
Option Description
--all-fields Includes all fields in the output.

plugin-settings

cloudsite plugin-settings [subcommand]

Command group for managing plugin settings.

plugin-settings options
Option Description
[subcommand] (main argument,required) The subcommand to execute.
Subcommands
  • set: Sets and deletes the specified options.
  • show: Displays the plugin settings for the specified site.

set

cloudsite plugin-settings set <options> [apex-domain]

Sets and deletes the specified options.

set options

Option Description
[apex-domain] (main argument,required) The apex domain of the site to configure.
--confirmed When entirely deleting (disabling) a plugin, you must either confirm interactively or provide the '--confirmed' option.
--delete When set, then deletes the setting. Incompatible with the '--value' option. To delete all plugin settings (disable the plugin), set '--name' or '--option' to the bare plugin name; e.g.: --value aPlugin.
--name The option name.
--option A combined name-value pair of plugin options in the form of: <name>:<value>. Can be used multiple times. When --delete is set, then the value is ignored and can be left blank.
--value The setting value. Incompatible with the '--delete' option.

show

cloudsite plugin-settings show [apex-domain]

Displays the plugin settings for the specified site.

show options

Option Description
[apex-domain] (main argument,required) The apex domain of the site whose settings are to be displayed.

reminders

cloudsite reminders [subcommand]

Command group for managing reminders.

reminders options
Option Description
[subcommand] (main argument,required) The subcommand to execute.
Subcommands
  • list: List currently active reminders.

list

cloudsite reminders list

List currently active reminders.

update

cloudsite update <options> [apex-domain]

Updates a website content and/or infrastructure.

update options
Option Description
[apex-domain] (main argument,required) The apex domain identifying the site.
--do-billing Limits updates to billing related matters (cost allocation tags) and other other specified updates.
--do-content Limits update to site content and any other specified updates.
--do-dns Limits update to DNS entries and any other specified updates.
--do-stack Limits update to stack infrastructure and any other specified updates.
--no-build Supresses the default behavior of building before updating the site.
--no-cache-invalidation Suppresses the default behavior of invalidating the CloudFront cache after the files are updated. Note that invalidation events are chargeable thought at the time of this writing, each account gets 1,000 free requests per year.

verify

cloudsite verify <options> [apex-domain]

Verifies the site is up and running and that the stack and content are up-to-date.

verify options
Option Description
[apex-domain] (main argument,required) The domain of the site to verify.
--check-content If set, then checks content and skips other checks unless also specifically specified.
--check-site-up If set, then checks that the site is up and skips other checks unless also specifically specified.
--check-stack If set, then checks for stack drift and skips other checks unless also specifically specified.

Known limitations

  • The permissions used by the 'ContactHandler' Lambda function are overly broad and need to be narrowed. See issue #34.

Contributing

Plase feel free to submit any bug reports or feature suggestions. You're also welcome to submit patches of course. We don't have a full contributors policy yet, but you can post questions on our discord channel. It's not monitored 24/7, but you should hear back from us by next business day generally.

Support and feature requests

The best way to get free support is to submit a ticket. You can also become a patron for as little as $1/month and get priority support and request new feature on all Liquid Labs open source software. You can get these benefits and support our work at patreon.com/liquidlabs.

Package Sidebar

Install

npm i cloudsite

Weekly Downloads

49

Version

1.0.0-beta.5

License

Apache-2.0

Unpacked Size

9.41 MB

Total Files

11

Last publish

Collaborators

  • zanerock