Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO-1554: Replace AWS Access Key Pair with Task Role #1118

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/prerender-fargate/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { PrerenderFargate } from "./lib/prerender-fargate";
import { PrerenderFargateOptions } from "./lib/prerender-fargate-options";
import { PrerenderTokenUrlAssociationOptions } from "./lib/recaching/prerender-tokens";

export { PrerenderFargate, PrerenderFargateOptions };
export {
PrerenderFargate,
PrerenderFargateOptions,
PrerenderTokenUrlAssociationOptions,
};
4 changes: 2 additions & 2 deletions packages/prerender-fargate/lib/prerender-fargate-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrerenderTokenUrlAssociationProps } from "./recaching/prerender-tokens";
import { PrerenderTokenUrlAssociationOptions } from "./recaching/prerender-tokens";

/**
* Options for configuring the Prerender Fargate construct.
Expand Down Expand Up @@ -77,5 +77,5 @@ export interface PrerenderFargateOptions {
* }
* ```
*/
tokenUrlAssociation?: PrerenderTokenUrlAssociationProps;
tokenUrlAssociation?: PrerenderTokenUrlAssociationOptions;
}
15 changes: 3 additions & 12 deletions packages/prerender-fargate/lib/prerender-fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
import { HostedZone } from "aws-cdk-lib/aws-route53";
import { Bucket, BlockPublicAccess } from "aws-cdk-lib/aws-s3";
import * as ecrAssets from "aws-cdk-lib/aws-ecr-assets";
import { AccessKey, User } from "aws-cdk-lib/aws-iam";
import { Duration, RemovalPolicy, Stack } from "aws-cdk-lib";
import * as path from "path";
import { PrerenderTokenUrlAssociation } from "./recaching/prerender-tokens";
Expand Down Expand Up @@ -115,15 +114,6 @@ export class PrerenderFargate extends Construct {
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
});

// Configure access to the bucket for the container
const user = new User(this, "PrerenderAccess");
this.bucket.grantReadWrite(user);

const accessKey = new AccessKey(this, "PrerenderAccessKey", {
user: user,
serial: 1,
});

const vpcLookup = vpcId ? { vpcId: vpcId } : { isDefault: true };
const vpc = ec2.Vpc.fromLookup(this, "vpc", vpcLookup);

Expand Down Expand Up @@ -165,8 +155,6 @@ export class PrerenderFargate extends Construct {
containerPort: 3000,
environment: {
S3_BUCKET_NAME: this.bucket.bucketName,
AWS_ACCESS_KEY_ID: accessKey.accessKeyId,
AWS_SECRET_ACCESS_KEY: accessKey.secretAccessKey.unsafeUnwrap(),
AWS_REGION: Stack.of(this).region,
ENABLE_REDIRECT_CACHE: enableRedirectCache || "false",
TOKEN_LIST: tokenList.toString(),
Expand All @@ -189,6 +177,9 @@ export class PrerenderFargate extends Construct {
}
);

// Grant S3 Bucket access to the task role
this.bucket.grantReadWrite(fargateService.taskDefinition.taskRole);

// As the prerender service will return a 401 on all unauthorised requests
// It should be considered healthy when receiving a 401 response
fargateService.targetGroup.configureHealthCheck({
Expand Down
4 changes: 2 additions & 2 deletions packages/prerender-fargate/lib/recaching/prerender-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface TokenUrlAssociation {
/**
* Interface for associating a token with a URL for prerendering.
*/
export interface PrerenderTokenUrlAssociationProps extends StackProps {
export interface PrerenderTokenUrlAssociationOptions extends StackProps {
/**
* Object containing the token and its associated URL.
* ### Example
Expand Down Expand Up @@ -46,7 +46,7 @@ export class PrerenderTokenUrlAssociation extends Stack {
constructor(
scope: Construct,
id: string,
props: PrerenderTokenUrlAssociationProps
props: PrerenderTokenUrlAssociationOptions
) {
super(scope, id, props);

Expand Down
Loading