-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(infra): Storage migrate to Gen 2 E2E
chore(infra): Storage migrate to Gen 2 E2E
- Loading branch information
1 parent
85fe599
commit d62d543
Showing
35 changed files
with
1,415 additions
and
311 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# amplify | ||
node_modules | ||
.amplify | ||
amplify_outputs* | ||
amplifyconfiguration* |
4 changes: 4 additions & 0 deletions
4
infra-gen2/backends/storage/dots-in-name/amplify/auth/pre-sign-up-handler.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,4 @@ | ||
import { PreSignUpTriggerHandler } from "aws-lambda"; | ||
import { preSignUpTriggerHandler } from "infra-common"; | ||
|
||
export const handler: PreSignUpTriggerHandler = preSignUpTriggerHandler; |
19 changes: 19 additions & 0 deletions
19
infra-gen2/backends/storage/dots-in-name/amplify/auth/resource.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,19 @@ | ||
import { defineAuth, defineFunction } from "@aws-amplify/backend"; | ||
|
||
export const preSignUp = defineFunction({ | ||
name: "pre-sign-up", | ||
entry: "./pre-sign-up-handler.ts", | ||
}); | ||
|
||
/** | ||
* Define and configure your auth resource | ||
* @see https://docs.amplify.aws/gen2/build-a-backend/auth | ||
*/ | ||
export const auth = defineAuth({ | ||
loginWith: { | ||
email: true, | ||
}, | ||
triggers: { | ||
preSignUp, | ||
}, | ||
}); |
40 changes: 40 additions & 0 deletions
40
infra-gen2/backends/storage/dots-in-name/amplify/backend.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,40 @@ | ||
import { defineBackend } from "@aws-amplify/backend"; | ||
import * as s3 from "aws-cdk-lib/aws-s3"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { auth } from "./auth/resource"; | ||
import { storage } from "./storage/resource"; | ||
|
||
/** | ||
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more | ||
*/ | ||
const backend = defineBackend({ | ||
auth, | ||
storage, | ||
}); | ||
|
||
// custom storage configurations | ||
const s3Bucket = backend.storage.resources.bucket; | ||
const cfnBucket = s3Bucket.node.defaultChild as s3.CfnBucket; | ||
|
||
const randomBucketName = `dots.in.name-${uuidv4()}`; | ||
|
||
cfnBucket.bucketName = randomBucketName; | ||
|
||
// required to add the metadata header, which amplify-backend does not support | ||
backend.storage.resources.cfnResources.cfnBucket.corsConfiguration = { | ||
corsRules: [ | ||
{ | ||
allowedHeaders: ["*"], | ||
allowedMethods: ["GET", "HEAD", "PUT", "POST", "DELETE"], | ||
allowedOrigins: ["*"], | ||
exposedHeaders: [ | ||
"x-amz-server-side-encryption", | ||
"x-amz-request-id", | ||
"x-amz-id-2", | ||
"ETag", | ||
"x-amz-meta-description", | ||
], | ||
maxAge: 3000, | ||
}, | ||
], | ||
}; |
3 changes: 3 additions & 0 deletions
3
infra-gen2/backends/storage/dots-in-name/amplify/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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
18 changes: 18 additions & 0 deletions
18
infra-gen2/backends/storage/dots-in-name/amplify/storage/resource.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,18 @@ | ||
import { defineStorage } from "@aws-amplify/backend"; | ||
|
||
export const storage = defineStorage({ | ||
name: "dots in name", | ||
access: (allow) => ({ | ||
"public/*": [ | ||
allow.guest.to(["read", "write", "delete"]), | ||
allow.authenticated.to(["read", "delete", "write"]), | ||
], | ||
"protected/{entity_id}/*": [ | ||
allow.authenticated.to(["read"]), | ||
allow.entity("identity").to(["read", "write", "delete"]), | ||
], | ||
"private/{entity_id}/*": [ | ||
allow.entity("identity").to(["read", "write", "delete"]), | ||
], | ||
}), | ||
}); |
17 changes: 17 additions & 0 deletions
17
infra-gen2/backends/storage/dots-in-name/amplify/tsconfig.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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "es2022", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"$amplify/*": [ | ||
"../.amplify/generated/*" | ||
] | ||
} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"name": "dots-in-name", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |
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,5 @@ | ||
# amplify | ||
node_modules | ||
.amplify | ||
amplify_outputs* | ||
amplifyconfiguration* |
4 changes: 4 additions & 0 deletions
4
infra-gen2/backends/storage/main/amplify/auth/pre-sign-up-handler.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,4 @@ | ||
import { PreSignUpTriggerHandler } from "aws-lambda"; | ||
import { preSignUpTriggerHandler } from "infra-common"; | ||
|
||
export const handler: PreSignUpTriggerHandler = preSignUpTriggerHandler; |
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,19 @@ | ||
import { defineAuth, defineFunction } from "@aws-amplify/backend"; | ||
|
||
export const preSignUp = defineFunction({ | ||
name: "pre-sign-up", | ||
entry: "./pre-sign-up-handler.ts", | ||
}); | ||
|
||
/** | ||
* Define and configure your auth resource | ||
* @see https://docs.amplify.aws/gen2/build-a-backend/auth | ||
*/ | ||
export const auth = defineAuth({ | ||
loginWith: { | ||
email: true, | ||
}, | ||
triggers: { | ||
preSignUp, | ||
}, | ||
}); |
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,39 @@ | ||
import { defineBackend } from "@aws-amplify/backend"; | ||
import * as s3 from "aws-cdk-lib/aws-s3"; | ||
import { auth } from "./auth/resource"; | ||
import { storage } from "./storage/resource"; | ||
|
||
/** | ||
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more | ||
*/ | ||
const backend = defineBackend({ | ||
auth, | ||
storage, | ||
}); | ||
|
||
// custom storage configurations | ||
const s3Bucket = backend.storage.resources.bucket; | ||
const cfnBucket = s3Bucket.node.defaultChild as s3.CfnBucket; | ||
|
||
cfnBucket.accelerateConfiguration = { | ||
accelerationStatus: "Enabled", | ||
}; | ||
|
||
// required to add the metadata header, which amplify-backend does not support | ||
backend.storage.resources.cfnResources.cfnBucket.corsConfiguration = { | ||
corsRules: [ | ||
{ | ||
allowedHeaders: ["*"], | ||
allowedMethods: ["GET", "HEAD", "PUT", "POST", "DELETE"], | ||
allowedOrigins: ["*"], | ||
exposedHeaders: [ | ||
"x-amz-server-side-encryption", | ||
"x-amz-request-id", | ||
"x-amz-id-2", | ||
"ETag", | ||
"x-amz-meta-description", | ||
], | ||
maxAge: 3000, | ||
}, | ||
], | ||
}; |
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
18 changes: 18 additions & 0 deletions
18
infra-gen2/backends/storage/main/amplify/storage/resource.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,18 @@ | ||
import { defineStorage } from "@aws-amplify/backend"; | ||
|
||
export const storage = defineStorage({ | ||
name: "Storage Integ Test main", | ||
access: (allow) => ({ | ||
"public/*": [ | ||
allow.guest.to(["read", "write", "delete"]), | ||
allow.authenticated.to(["read", "delete", "write"]), | ||
], | ||
"protected/{entity_id}/*": [ | ||
allow.authenticated.to(["read"]), | ||
allow.entity("identity").to(["read", "write", "delete"]), | ||
], | ||
"private/{entity_id}/*": [ | ||
allow.entity("identity").to(["read", "write", "delete"]), | ||
], | ||
}), | ||
}); |
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "es2022", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"$amplify/*": [ | ||
"../.amplify/generated/*" | ||
] | ||
} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"name": "main", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |
Oops, something went wrong.