-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,71 @@ | ||
import { Stack, aws_s3 as s3, aws_s3_deployment as s3_deployment} from "aws-cdk-lib"; | ||
import { RemovalPolicy, CfnOutput } from "aws-cdk-lib"; | ||
import { PolicyStatement, ServicePrincipal, Effect } from "aws-cdk-lib/aws-iam"; | ||
|
||
import { Construct } from "constructs"; | ||
|
||
|
||
export class StacBrowser extends Construct { | ||
|
||
public bucket: s3.Bucket; | ||
public bucket_deployment: s3_deployment.BucketDeployment; | ||
|
||
constructor(scope: Construct, id: string, props: StacBrowserProps) { | ||
super(scope, id); | ||
|
||
const bucket = new s3.Bucket(this, 'Bucket', { | ||
accessControl: s3.BucketAccessControl.PRIVATE, | ||
removalPolicy: RemovalPolicy.DESTROY, | ||
}) | ||
|
||
bucket.addToResourcePolicy(new PolicyStatement({ | ||
sid: 'AllowCloudFrontServicePrincipal', | ||
effect: Effect.ALLOW, | ||
actions: ['s3:GetObject'], | ||
principals: [new ServicePrincipal('cloudfront.amazonaws.com')], | ||
resources: [bucket.arnForObjects('*')], | ||
conditions: { | ||
'StringEquals': { | ||
'aws:SourceArn': props.cloudFrontDistributionArn | ||
} | ||
} | ||
})); | ||
|
||
|
||
const browser_deployment = new s3_deployment.BucketDeployment(this, 'BucketDeployment', { | ||
destinationBucket: bucket, | ||
sources: [s3_deployment.Source.asset(props.stacBrowserDistPath)] | ||
}); | ||
|
||
new CfnOutput(this, "bucket-name", { | ||
exportName: `${Stack.of(this).stackName}-bucket-name`, | ||
value: bucket.bucketName, | ||
}); | ||
|
||
} | ||
} | ||
|
||
export interface StacBrowserProps { | ||
|
||
/** | ||
* Location of the directory in the local filesystem that contains the STAC browser compiled code. | ||
*/ | ||
stacBrowserDistPath: string; | ||
|
||
|
||
/** | ||
* The ARN of the cloudfront distribution that will be added to the bucket policy with read access. | ||
* | ||
* @default - No cloudfront distribution ARN. The bucket policy will not be modified. | ||
*/ | ||
cloudFrontDistributionArn?: string; | ||
|
||
/** | ||
* The name of the index document (e.g. "index.html") for the website. Enables static website | ||
* hosting for this bucket. | ||
* | ||
* @default - No index document. | ||
*/ | ||
websiteIndexDocument?: string; | ||
|
||
} |