runway.cfngin.hooks.staticsite.upload_staticsite module

CFNgin hook for syncing static website to S3 bucket.

pydantic model runway.cfngin.hooks.staticsite.upload_staticsite.HookArgs[source]

Bases: HookArgsBaseModel

Hook arguments.

Show JSON schema
{
   "title": "HookArgs",
   "description": "Hook arguments.",
   "type": "object",
   "properties": {
      "tags": {
         "additionalProperties": {
            "type": "string"
         },
         "default": {},
         "title": "Tags",
         "type": "object"
      },
      "bucket_name": {
         "title": "Bucket Name",
         "type": "string"
      },
      "cf_disabled": {
         "default": false,
         "title": "Cf Disabled",
         "type": "boolean"
      },
      "distribution_domain": {
         "default": "undefined",
         "title": "Distribution Domain",
         "type": "string"
      },
      "distribution_id": {
         "default": "undefined",
         "title": "Distribution Id",
         "type": "string"
      },
      "distribution_path": {
         "default": "/*",
         "title": "Distribution Path",
         "type": "string"
      },
      "extra_files": {
         "default": [],
         "items": {
            "$ref": "#/$defs/RunwayStaticSiteExtraFileDataModel"
         },
         "title": "Extra Files",
         "type": "array"
      },
      "website_url": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Website Url"
      }
   },
   "$defs": {
      "RunwayStaticSiteExtraFileDataModel": {
         "additionalProperties": false,
         "description": "Model for Runway static site Module extra_files option item.",
         "properties": {
            "content_type": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Content Type"
            },
            "content": {
               "default": null,
               "title": "Content"
            },
            "file": {
               "anyOf": [
                  {
                     "format": "path",
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "File"
            },
            "name": {
               "title": "Name",
               "type": "string"
            }
         },
         "required": [
            "name"
         ],
         "title": "Runway static site Module extra_files option item",
         "type": "object"
      }
   },
   "required": [
      "bucket_name"
   ]
}

field bucket_name: str = PydanticUndefined

S3 bucket name.

field cf_disabled: bool = False

Disable the use of CloudFront.

field distribution_domain: str = 'undefined'

Domain of the CloudFront distribution.

field distribution_id: str = 'undefined'

CloudFront distribution ID.

field distribution_path: str = '/*'

Path in the CloudFront distribution to invalidate.

field extra_files: list[RunwayStaticSiteExtraFileDataModel] = []

Extra files to sync to the S3 bucket.

field website_url: str | None = None

S3 bucket website URL.

runway.cfngin.hooks.staticsite.upload_staticsite.auto_detect_content_type(filename: str | None) str | None[source]

Auto detects the content type based on the filename.

Parameters:

filename – A filename to use to auto detect the content type.

Returns:

The content type of the file. None if the content type could not be detected.

runway.cfngin.hooks.staticsite.upload_staticsite.calculate_hash_of_extra_files(extra_files: list[RunwayStaticSiteExtraFileDataModel]) str[source]

Return a hash of all of the given extra files.

All attributes of the extra file object are included when hashing: name, content_type, content, and file data.

Parameters:

extra_files – The list of extra file configurations.

Returns:

The hash of all the files.

runway.cfngin.hooks.staticsite.upload_staticsite.get_archives_to_prune(archives: list[dict[str, Any]], hook_data: dict[str, Any]) list[str][source]

Return list of keys to delete.

Parameters:
  • archives – The full list of file archives

  • hook_data – CFNgin hook data

runway.cfngin.hooks.staticsite.upload_staticsite.get_content(extra_file: RunwayStaticSiteExtraFileDataModel) str | None[source]

Get serialized content based on content_type.

Parameters:

extra_file – The extra file configuration.

Returns:

Serialized content based on the content_type.

runway.cfngin.hooks.staticsite.upload_staticsite.get_content_type(extra_file: RunwayStaticSiteExtraFileDataModel) str | None[source]

Return the content type of the file.

Parameters:

extra_file – The extra file configuration.

Returns:

The content type of the extra file. If ‘content_type’ is provided then that is returned, otherwise it is auto detected based on the name.

runway.cfngin.hooks.staticsite.upload_staticsite.get_ssm_value(session: Session, name: str) str | None[source]

Get the ssm parameter value.

Parameters:
  • session – The boto3 session.

  • name – The parameter name.

Returns:

The parameter value.

runway.cfngin.hooks.staticsite.upload_staticsite.invalidate_distribution(session: Session, *, domain: str = 'undefined', identifier: str, path: str = '/*', **_: Any) bool[source]

Invalidate the current distribution.

Parameters:
  • session – The current CFNgin session.

  • domain – The distribution domain.

  • identifier – The distribution id.

  • path – The distribution path.

runway.cfngin.hooks.staticsite.upload_staticsite.prune_archives(context: CfnginContext, session: Session) bool[source]

Prune the archives from the bucket.

Parameters:
  • context – The context instance.

  • session – The CFNgin session.

runway.cfngin.hooks.staticsite.upload_staticsite.set_ssm_value(session: Session, name: str, value: Any, description: str = '') None[source]

Set the ssm parameter.

Parameters:
  • session – The boto3 session.

  • name – The name of the parameter.

  • value – The value of the parameter.

  • description – A description of the parameter.

runway.cfngin.hooks.staticsite.upload_staticsite.sync(context: runway.context.CfnginContext, *__args: Any, **kwargs: Any) bool[source]

Sync static website to S3 bucket.

Arguments parsed by HookArgs.

Parameters:
  • context – The context instance.

  • **kwargs – Arbitrary keyword arguments.

runway.cfngin.hooks.staticsite.upload_staticsite.sync_extra_files(context: runway.context.CfnginContext, bucket: str, extra_files: list[RunwayStaticSiteExtraFileDataModel], **kwargs: Any) list[str][source]

Sync static website extra files to S3 bucket.

Parameters:
  • context – The context instance.

  • bucket – The static site bucket name.

  • extra_files – List of files and file content that should be uploaded.

  • **kwargs – Arbitrary keyword arguments.

runway.cfngin.hooks.staticsite.upload_staticsite.update_ssm_hash(context: CfnginContext, session: Session) bool[source]

Update the SSM hash with the new tracking data.

Parameters:
  • context – Context instance.

  • session – boto3 session.