-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-cloudfront-mediastore): new aws-cloudfront-mediastore patter…
…n implementation
- Loading branch information
1 parent
c28e680
commit 923455e
Showing
25 changed files
with
2,821 additions
and
2 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/.eslintignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
lib/*.js | ||
test/*.js | ||
*.d.ts | ||
coverage |
16 changes: 16 additions & 0 deletions
16
source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
lib/*.js | ||
test/*.js | ||
!test/lambda/* | ||
*.js.map | ||
*.d.ts | ||
node_modules | ||
*.generated.ts | ||
dist | ||
.jsii | ||
|
||
.LAST_BUILD | ||
.nyc_output | ||
coverage | ||
.nycrc | ||
.LAST_PACKAGE | ||
*.snk |
21 changes: 21 additions & 0 deletions
21
source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/.npmignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Exclude typescript source and config | ||
*.ts | ||
tsconfig.json | ||
coverage | ||
.nyc_output | ||
*.tgz | ||
*.snk | ||
*.tsbuildinfo | ||
|
||
# Include javascript files and typescript declarations | ||
!*.js | ||
!*.d.ts | ||
|
||
# Exclude jsii outdir | ||
dist | ||
|
||
# Include .jsii | ||
!.jsii | ||
|
||
# Include .jsii | ||
!.jsii |
89 changes: 89 additions & 0 deletions
89
source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# aws-cloudfront-mediastore module | ||
<!--BEGIN STABILITY BANNER--> | ||
|
||
--- | ||
|
||
![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge) | ||
|
||
> All classes are under active development and subject to non-backward compatible changes or removal in any | ||
> future version. These are not subject to the [Semantic Versioning](https://semver.org/) model. | ||
> This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package. | ||
--- | ||
<!--END STABILITY BANNER--> | ||
|
||
| **Reference Documentation**:| <span style="font-weight: normal">https://docs.aws.amazon.com/solutions/latest/constructs/</span>| | ||
|:-------------|:-------------| | ||
<div style="height:8px"></div> | ||
|
||
|
||
| **Language** | **Package** | | ||
|:-------------|-----------------| | ||
|![Python Logo](https://docs.aws.amazon.com/cdk/api/latest/img/python32.png) Python|`aws_solutions_constructs.aws_cloudfront_mediastore`| | ||
|![TypeScript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) TypeScript|`@aws-solutions-constructs/aws-cloudfront-mediastore`| | ||
|![Java Logo](https://docs.aws.amazon.com/cdk/api/latest/img/java32.png) Java|`software.amazon.awsconstructs.services.cloudfrontmediastore`| | ||
|
||
## Overview | ||
This AWS Solutions Construct implements an Amazon CloudFront distribution to an AWS Elemental MediaStore container. | ||
|
||
Here is a minimal deployable pattern definition in TypeScript: | ||
|
||
``` typescript | ||
import { CloudFrontToMediaStore } from '@aws-solutions-constructs/aws-cloudfront-mediastore'; | ||
|
||
new CloudFrontToMediaStore(this, 'test-cloudfront-mediastore-default', {}); | ||
|
||
``` | ||
|
||
## Initializer | ||
|
||
``` text | ||
new CloudFrontToMediaStore(scope: Construct, id: string, props: CloudFrontToMediaStoreProps); | ||
``` | ||
|
||
_Parameters_ | ||
|
||
* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html) | ||
* id `string` | ||
* props [`CloudFrontToMediaStoreProps`](#pattern-construct-props) | ||
|
||
## Pattern Construct Props | ||
|
||
| **Name** | **Type** | **Description** | | ||
|:-------------|:----------------|-----------------| | ||
|exsistingMediaStoreContainerObj?|[`mediastore.CfnContainer`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-mediastore.CfnContainer.html)|Optional user provided MediaStore container to override the default MediaStore container.| | ||
|mediaStoreContainerProps?|[`mediastore.CfnContainerProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-mediastore.CfnContainerProps.html)|Optional user provided props to override the default props for the MediaStore Container.| | ||
|cloudFrontDistributionProps?|[`cloudfront.DistributionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.DistributionProps.html)\|`any`|Optional user provided props to override the default props for the CloudFront Distribution.| | ||
|
||
## Pattern Properties | ||
|
||
| **Name** | **Type** | **Description** | | ||
|:-------------|:----------------|-----------------| | ||
|cloudFrontWebDistribution|[`cloudfront.CloudFrontWebDistribution`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.CloudFrontWebDistribution.html)|Returns an instance of the CloudFront Web Distribution created by the construct.| | ||
|mediaStoreContainer|[`mediastore.CfnContainer`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-mediastore.CfnContainer.html)|Returns an instance of the MediaStore Container.| | ||
|cloudFrontLoggingBucket|[`s3.Bucket`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.Bucket.html)|Returns an instance of the logging S3 bucket for CloudFront Web Distribution.| | ||
|cloudFrontOriginRequestPolicy|[`cloudfront.OriginRequestPolicy`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.OriginRequestPolicy.html)|Returns an instance of the CloudFront Origin Request Policye created by the construct for CloudFront Web Distribution.| | ||
|cloudFrontOriginAccessIdentity?|[`cloudfront.OriginAccessIdentity`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudfront.OriginAccessIdentity.html)|Returns an instance of the CloudFront Origin Access Identity created by the construct for the CloudFront Web Distribution origin custom headers and the MediaStore Container policy.| | ||
|
||
## Default settings | ||
|
||
Out of the box implementation of the Construct without any override will set the following defaults: | ||
|
||
### Amazon CloudFront | ||
* Configure access logging for CloudFront Web Distribution | ||
* Enable CloudFront Origin Request Policy for AWS Elemental MediaStore Container | ||
* Set `User-Agent` custom header with CloudFront Origin Access Identity | ||
|
||
### AWS Elemental MediaStore | ||
* Set the deletion policy to retain the resource | ||
* Set the container name with the CloudFormation stack name | ||
* Set the default [Container Cross-origin resource sharing (CORS) policy](https://docs.aws.amazon.com/mediastore/latest/ug/cors-policy.html) | ||
* Set the default [Object Life Cycle policy](https://docs.aws.amazon.com/mediastore/latest/ug/policies-object-lifecycle.html) | ||
* Set the default [Container Policy](https://docs.aws.amazon.com/mediastore/latest/ug/policies.html) to allow only `aws:UserAgent` with CloudFront Origin Access Identity | ||
* Enable the access logging | ||
|
||
## Architecture | ||
![Architecture Diagram](architecture.png) | ||
|
||
*** | ||
© Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
Binary file added
BIN
+99.4 KB
...e/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions
117
source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance | ||
* with the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES | ||
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
|
||
import * as cloudfront from '@aws-cdk/aws-cloudfront'; | ||
import * as mediastore from '@aws-cdk/aws-mediastore'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
import * as defaults from '@aws-solutions-constructs/core'; | ||
import { Construct, Aws} from '@aws-cdk/core'; | ||
import { MediaStoreContainer } from '../../core/lib/mediastore-helper'; | ||
|
||
/** | ||
* @summary The properties for the CloudFrontToMediaStore Construct | ||
*/ | ||
export interface CloudFrontToMediaStoreProps { | ||
/** | ||
* Existing instance of mediastore.CfnContainer obejct. | ||
* | ||
* @default - None | ||
*/ | ||
readonly existingMediaStoreContainerObj?: mediastore.CfnContainer; | ||
/** | ||
* Optional user provided props to override the default props for the MediaStore. | ||
* | ||
* @default - Default props are used | ||
*/ | ||
readonly mediaStoreContainerProps?: mediastore.CfnContainerProps; | ||
/** | ||
* Optional user provided props to override the default props for the CloudFront. | ||
* | ||
* @default - Default props are used | ||
*/ | ||
readonly cloudFrontDistributionProps?: cloudfront.DistributionProps | any; | ||
} | ||
|
||
export class CloudFrontToMediaStore extends Construct { | ||
public readonly cloudFrontWebDistribution: cloudfront.Distribution; | ||
public readonly mediaStoreContainer: mediastore.CfnContainer; | ||
public readonly cloudFrontLoggingBucket: s3.Bucket; | ||
public readonly cloudFrontOriginRequestPolicy: cloudfront.OriginRequestPolicy; | ||
public readonly cloudFrontOriginAccessIdentity?: cloudfront.OriginAccessIdentity; | ||
|
||
/** | ||
* @summary Constructs a new instance of CloudFrontToMediaStore class. | ||
* @param {cdk.App} scope - represents the scope for all the resources. | ||
* @param {string} id - this is a scope-unique id. | ||
* @param {CloudFrontToMediaStoreProps} props - user provided props for the construct | ||
* @since 1.75.0 | ||
* @access public | ||
*/ | ||
constructor(scope: Construct, id: string, props: CloudFrontToMediaStoreProps) { | ||
super (scope, id); | ||
|
||
let cloudFrontDistributionProps = props.cloudFrontDistributionProps; | ||
|
||
if (props.existingMediaStoreContainerObj) { | ||
this.mediaStoreContainer = props.existingMediaStoreContainerObj; | ||
} else { | ||
let mediaStoreProps: mediastore.CfnContainerProps; | ||
|
||
if (props.mediaStoreContainerProps) { | ||
mediaStoreProps = props.mediaStoreContainerProps; | ||
} else { | ||
this.cloudFrontOriginAccessIdentity = defaults.CloudFrontOriginAccessIdentity(scope); | ||
|
||
mediaStoreProps = { | ||
containerName: Aws.STACK_NAME, | ||
policy: JSON.stringify({ | ||
Version: '2012-10-17', | ||
Statement: [{ | ||
Sid: 'MediaStoreDefaultPolicy', | ||
Effect: 'Allow', | ||
Principal: '*', | ||
Action: [ | ||
'mediastore:GetObject', | ||
'mediastore:DescribeObject' | ||
], | ||
Resource: `arn:${Aws.PARTITION}:mediastore:${Aws.REGION}:${Aws.ACCOUNT_ID}:container/${Aws.STACK_NAME}/*`, | ||
Condition: { | ||
Bool: { | ||
'aws:UserAgent': this.cloudFrontOriginAccessIdentity.originAccessIdentityName, | ||
'aws:SecureTransport': 'true' | ||
} | ||
} | ||
}] | ||
}) | ||
}; | ||
|
||
const userAgentHeader: Record<string, string> = { | ||
'User-Agent': this.cloudFrontOriginAccessIdentity.originAccessIdentityName | ||
}; | ||
|
||
if (cloudFrontDistributionProps) { | ||
cloudFrontDistributionProps.customHeaders = userAgentHeader; | ||
} else { | ||
cloudFrontDistributionProps = { | ||
customHeaders: userAgentHeader | ||
}; | ||
} | ||
} | ||
|
||
this.mediaStoreContainer = MediaStoreContainer(scope, mediaStoreProps); | ||
} | ||
|
||
[this.cloudFrontWebDistribution, this.cloudFrontLoggingBucket, this.cloudFrontOriginRequestPolicy] | ||
= defaults.CloudFrontDistributionForMediaStore(scope, this.mediaStoreContainer, cloudFrontDistributionProps); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"name": "@aws-solutions-constructs/aws-cloudfront-mediastore", | ||
"version": "0.0.0", | ||
"description": "CDK Constructs for Amazon CloudFront to AWS Elemental MediaStore integration.", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/awslabs/aws-solutions-constructs.git", | ||
"directory": "source/patterns/@aws-solutions-constructs/aws-cloudfront-mediastore" | ||
}, | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com", | ||
"organization": true | ||
}, | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "tsc -b .", | ||
"lint": "eslint -c ../eslintrc.yml --ext=.js,.ts . && tslint --project .", | ||
"lint-fix": "eslint -c ../eslintrc.yml --ext=.js,.ts --fix .", | ||
"test": "jest --coverage", | ||
"clean": "tsc -b --clean", | ||
"watch": "tsc -b -w", | ||
"integ": "cdk-integ", | ||
"integ-no-clean": "cdk-integ --no-clean", | ||
"integ-assert": "cdk-integ-assert", | ||
"jsii": "jsii", | ||
"jsii-pacmak": "jsii-pacmak", | ||
"build+lint+test": "npm run jsii && npm run lint && npm test && npm run integ-assert", | ||
"snapshot-update": "npm run jsii && npm test -- -u && npm run integ-assert" | ||
}, | ||
"jsii": { | ||
"outdir": "dist", | ||
"targets": { | ||
"java": { | ||
"package": "software.amazon.awsconstructs.services.cloudfrontmediastore", | ||
"maven": { | ||
"groupId": "software.amazon.awsconstructs", | ||
"artifactId": "cloudfrontmediastore" | ||
} | ||
}, | ||
"dotnet": { | ||
"namespace": "Amazon.Constructs.AWS.CloudfrontMediastore", | ||
"packageId": "Amazon.Constructs.AWS.CloudfrontMediastore", | ||
"signAssembly": true, | ||
"iconUrl": "https://raw.githubusercontent.com/aws/aws-cdk/master/logo/default-256-dark.png" | ||
}, | ||
"python": { | ||
"distName": "aws-solutions-constructs.aws-cloudfront-mediastore", | ||
"module": "aws_solutions_constructs.aws_cloudfront_mediastore" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"@aws-cdk/core": "0.0.0", | ||
"@aws-cdk/aws-cloudfront": "0.0.0", | ||
"@aws-cdk/aws-mediastore": "0.0.0", | ||
"@aws-cdk/aws-s3": "0.0.0", | ||
"@aws-solutions-constructs/core": "0.0.0", | ||
"constructs": "^3.2.27" | ||
}, | ||
"devDependencies": { | ||
"@aws-cdk/assert": "0.0.0", | ||
"@types/jest": "^24.0.23", | ||
"@types/node": "^10.3.0" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js" | ||
] | ||
}, | ||
"peerDependencies": { | ||
"@aws-cdk/core": "0.0.0", | ||
"@aws-cdk/aws-cloudfront": "0.0.0", | ||
"@aws-cdk/aws-mediastore": "0.0.0", | ||
"@aws-cdk/aws-s3": "0.0.0", | ||
"@aws-solutions-constructs/core": "0.0.0", | ||
"constructs": "^3.2.27" | ||
} | ||
} |
Oops, something went wrong.