2.1.9 • Published 9 months ago

@evokegroup/aws-deployment v2.1.9

Weekly downloads
15
License
ISC
Repository
-
Last release
9 months ago

@evokegroup/aws-deployment

Provides AWS deployments via JSON configuration files. JSON with comments is supported when the file extension is .jsonc. Settings in the format ${VARIABLE_NAME} will be replaced with the environment variable value.

// config.json
{
  "settings": {
    "cloudFront": {
      "id": "${CLOUDFRONT_DISTRIBUTION_ID}"
    },
    "s3": {
      "bucket": "${S3_BUCKET_NAME}"
    }
  },
  "deployment": {
    "steps": {
      "s3.uploadFiles": {
        "directory": "static/dist",
        "ignore": [
          "^.*\\.htaccess$"
        ]
      },
      "s3.redirects": {
        "redirects": "aws-redirects.jsonc"
      },
      "s3.redirectionRules": {
        "rules": "aws-redirection-rules.json"
      },
      "cloudFront.invalidate": {},
      "s3.removeNotDeployed": {}
    }
  }
}
const awsDeploy = require('@evokegroup/aws-deployment');
awsDeploy({
  config: 'config.json'
})
  .then(() => {
    // done
  })
  .catch((err) => {
    // error
  });

The deployment can perform the same step multiple times by setting deployment.steps to an Array<object>.

// config.json
{
  "deployment": {
    "steps": [{
      "s3.uploadFiles": {
        "bucket": "${S3_BUCKET_ENGLISH}",
        "directory": "static/dist",
        "ignore": [
          "^fr\\/.*$"
        ]
      }
    }, {
      "s3.uploadFiles": {
        "bucket": "${S3_BUCKET_FRENCH}",
        "directory": "static/dist/fr"
      }
    }]
  }
}

Settings: CloudFront

PropertyTypeDefaultDescription
idstring${CLOUDFRONT_DISTRIBUTION_ID}The CloudFront distribution ID or environment variable name as ${ENV_VAR_NAME}
pathsArray<string>["/*"]The invalidation paths
{
  "settings": {
    "cloudFront": {
      "id": "ABC123"
    }
  }
}
{
  "settings": {
    "cloudFront": {
      "id": "${CLOUDFRONT_ID}"
    }
  }
}


## Settings: S3
  
| Property | Type | Default | Description |
| -------- | ---- | ------- | ----------- |
| bucket | `string` | `${S3_BUCKET_NAME}` | The S3 bucket name or environment variable name as ${ENV_VAR_NAME} |
  
  
```json
{
  "settings": {
    "s3": {
      "bucket": "bucket-name",
    }
  }
}
{
  "settings": {
    "s3": {
      "bucket": "${S3_BUCKET_NAME}",
    }
  }
}

Deployment Step: All Steps

PropertyTypeDefaultDescription
enabledbooleantrueIs the step enabled
{
  "deployment": {
    "steps": {
      "step.name": {
        "enabled": true
      }
    }
  }
}

Deployment Step: cloudFront.invalidate

Invalidates paths within a CloudFront distribution

PropertyTypeDefaultDescription
idstringsettings.cloudFront.idThe CloudFront distribution id
pathsArray<string>settings.cloudFront.pathsThe invalidation paths
{
  "deployment": {
    "steps": {
      "cloudFront.invalidate": {
        "id": "OVERRIDE",
        "paths": ["OVERRIDE"]
      }
    }
  }
}

Deployment Step: s3.archive

Creates a zip archive and uploads it to an S3 bucket.

PropertyTypeDefaultDescription
bucketstringsettings.s3.bucketThe S3 bucket name
prefixstringA bucket path prefix to append to to key
directorystringThe directory containing the files to upload
fileNamestringThe generated ZIP file name. If this is undefined, null or empty, a file name will be automatically generated based on other settings.
separatorstring_File name separator
timestampbooleanfalseAppend a timestamp to the file name. Defaults to and ISO string with : and . replaced with -.
timestampFormatstringThe date/time format string. See @evokegroup/dateformat.
timestampRadixnumberThe radix to use for converting the Date into a string when a timestampFormat is not specified.
guidbooleanfalseAppends a guid to the file name.
ignoreArray<string>, Array<RegExp>[]Files to ignore when uploading
{
  "s3.archive": {
    "enabled": "${S3_ARCHIVE_ENABLED}",
    "bucket": "${S3_ARCHIVE}",
    "directory": "static/dist",
    "fileName": "archive",
    "timestamp": true
  }
}

Deployment Step: s3.redirectionRules

Sets the static website host redirection rules property.

See https://docs.aws.amazon.com/AmazonS3/latest/dev/how-to-page-redirect.html#advanced-conditional-redirects

PropertyTypeDefaultDescription
bucketstringsettings.s3.bucketThe S3 bucket name
rulesArray<object>, stringAn array of objects or a file containing the redirection rules.
{
  "deployment": {
    "steps": {
      "s3.redirectionRules": {
        "bucket": "OVERRIDE",
        "rules": "aws-redirection-rules.json"
      }
    }
  }
}

Deployment Step: s3.redirects

Creates redirects in S3 by creating an empty file with the redirect specified in it's metadata.

PropertyTypeDefaultDescription
bucketstringsettings.s3.bucketThe S3 bucket name
redirectsobject, string{}An object or a file containing the paths to be redirected and the redirect locations
{
  "deployment": {
    "steps": {
      "s3.redirects": {
        "bucket": "OVERRIDE",
        "redirects": "aws-redirects.jsonc"
      }
    }
  }
}
// aws-redirects.jsonc
{
  // Comments are supported in .jsonc file
  "/some-page": "/somewhere-else", 
  "/another-page": {
    "subpaths": ["index", "index.html"], // redirect /another-path/index and /another-path/index.html
    "redirect": "/go-here",
    "meta": {
      "Cache-Control": "max-age=3600, no-transform, public"
    }
  }
}

Redirect Object

PropertyTypeDefaultDescription
keystringThe path to be redirected. A leading / is optional.
valueobject, stringThe path to redirect to or an object containing the redirect information. The redirect path should start with / if not redirecting to another domain.
value.altsArray<string>An array of alternate paths to be redirected.
value.extsArray<string>An array of extensions to append to the path to be redirected.
value.subpathsArray<string>An array of subpaths that should also be redirected.
value.redirectstringThe redirect path.
value.queryobjectQuery string data object
value.metaobjectOverride S3 metadata
value.redirectHeaderstringx-amz-website-redirect-locationThe redirect header name. Override this if using the standard S3 object redirection method in not desired and the redirection will be provided by another means.
value.trackbooleanfalseAdd tracking info
value.trackMethodstringquerystringAdd tracking info via querystring or header
value.trackDataobject, stringevo_redirected=${from}Tracking data. string values must be in the standard query string format. Values of ${from} will be replaced with the path being redirected. Values of ${to} will be replaced with the path being redirected to.

Basic redirect.

{
  "/vanity-url": "/real-url/?utm_source=test"
}

Redirect /vanity-url, /vanity-url.html, and /vanity-url/index.html.

{
  "/vanity-url": {
    "alts": [
      "/vanity-url.html",
      "/vanity-url/index.html"
    ],
    "redirect": "/real-url/",
    "query": {
      "utm_source": "test"
    }
  }
}

Redirect /external-url, /external-url.html, and /external-url/index.html and do not track.

{
  "/external-url": {
    "exts": [
      ".html"
    ],
    "subpaths": [
      "index.html"
    ],
    "redirect": "https://www.domain.com/path?other=data",
    "track": false
  }
}

Set tracking for all redirects.

{
  "deployment": {
    "steps": {
      "s3.redirects": {
        "redirects": "aws-redirects.jsonc",
        "track": true,
        "trackData": "from=${from}"
      }
    }
  }
}

Don't use an external file.

{
  "deployment": {
    "steps": {
      "s3.redirects": {
        "redirects": {
          "/redirect-me": "/go-here/"
        },
        "track": true,
        "trackData": {
          "from": "${from}",
          "to": "${to}"
        }
      }
    }
  }
}

Deployment Step: s3.removeNotDeployed

Removes any files not included in the deployment.

PropertyTypeDefaultDescription
bucketstringsettings.s3.bucketThe S3 bucket name
removeFilesbooleantrueRemove files
removeRedirectsbooleantrueRemove redirects
removeAnyCreatorbooleantrueRemove a file or redirect regardless of how the file was created. To remove only files created with the library set to false
ignoreArray<RegExp>[]An array of regular expressions of files that should not be deleted
{
  "deployment": {
    "steps": {
      "s3.removeNotDeployed": {
        "bucket": "OVERRIDE",
        "ignore": [
          "^do-not-delete.txt$"
        ]
      }
    }
  }
}

Deployment Step: s3.uploadFiles

Uploads a directory to S3.

PropertyTypeDefaultDescription
bucketstringsettings.s3.bucketThe S3 bucket name
prefixstringA bucket path prefix to add to every file
directorystringnullThe directory containing the files to upload
ignoreArray<RegExp>[]Files to ignore when uploading
metaobject{}S3 metadata. Extends the standard configuration (services.s3.meta)
onlyChangedbooleantrueOnly upload files who's ETag is different
{
  "deployment": {
    "steps": {
      "s3.uploadFiles": {
        "bucket": "OVERRIDE",
        "directory": "static/dist",
        "ignore": [
          "^.*\\.htaccess$"
        ]
      }
    }
  }
}

Upload to multiple buckets

{
  "deployment": {
    "steps": [{
      "s3.uploadFiles": {
        "bucket": "${S3_BUCKET_ENGLISH}",
        "directory": "static/dist",
        "ignore": [
          "^fr\\/.*$"
        ]
      }
    }, {
      "s3.uploadFiles": {
        "bucket": "${S3_BUCKET_FRENCH}",
        "directory": "static/dist/fr"
      }
    }]
  }
}
2.1.9

9 months ago

2.1.8

1 year ago

2.1.4

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.7

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.0.7

2 years ago

2.1.0

2 years ago

2.0.6

2 years ago

2.0.5

3 years ago

2.0.3

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.15

3 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.11

4 years ago

1.0.12

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago