Skip to content

Commit d62d543

Browse files
chore(infra): Storage migrate to Gen 2 E2E
chore(infra): Storage migrate to Gen 2 E2E
1 parent 85fe599 commit d62d543

35 files changed

+1415
-311
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# amplify
2+
node_modules
3+
.amplify
4+
amplify_outputs*
5+
amplifyconfiguration*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PreSignUpTriggerHandler } from "aws-lambda";
2+
import { preSignUpTriggerHandler } from "infra-common";
3+
4+
export const handler: PreSignUpTriggerHandler = preSignUpTriggerHandler;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineAuth, defineFunction } from "@aws-amplify/backend";
2+
3+
export const preSignUp = defineFunction({
4+
name: "pre-sign-up",
5+
entry: "./pre-sign-up-handler.ts",
6+
});
7+
8+
/**
9+
* Define and configure your auth resource
10+
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
11+
*/
12+
export const auth = defineAuth({
13+
loginWith: {
14+
email: true,
15+
},
16+
triggers: {
17+
preSignUp,
18+
},
19+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { defineBackend } from "@aws-amplify/backend";
2+
import * as s3 from "aws-cdk-lib/aws-s3";
3+
import { v4 as uuidv4 } from "uuid";
4+
import { auth } from "./auth/resource";
5+
import { storage } from "./storage/resource";
6+
7+
/**
8+
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
9+
*/
10+
const backend = defineBackend({
11+
auth,
12+
storage,
13+
});
14+
15+
// custom storage configurations
16+
const s3Bucket = backend.storage.resources.bucket;
17+
const cfnBucket = s3Bucket.node.defaultChild as s3.CfnBucket;
18+
19+
const randomBucketName = `dots.in.name-${uuidv4()}`;
20+
21+
cfnBucket.bucketName = randomBucketName;
22+
23+
// required to add the metadata header, which amplify-backend does not support
24+
backend.storage.resources.cfnResources.cfnBucket.corsConfiguration = {
25+
corsRules: [
26+
{
27+
allowedHeaders: ["*"],
28+
allowedMethods: ["GET", "HEAD", "PUT", "POST", "DELETE"],
29+
allowedOrigins: ["*"],
30+
exposedHeaders: [
31+
"x-amz-server-side-encryption",
32+
"x-amz-request-id",
33+
"x-amz-id-2",
34+
"ETag",
35+
"x-amz-meta-description",
36+
],
37+
maxAge: 3000,
38+
},
39+
],
40+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineStorage } from "@aws-amplify/backend";
2+
3+
export const storage = defineStorage({
4+
name: "dots in name",
5+
access: (allow) => ({
6+
"public/*": [
7+
allow.guest.to(["read", "write", "delete"]),
8+
allow.authenticated.to(["read", "delete", "write"]),
9+
],
10+
"protected/{entity_id}/*": [
11+
allow.authenticated.to(["read"]),
12+
allow.entity("identity").to(["read", "write", "delete"]),
13+
],
14+
"private/{entity_id}/*": [
15+
allow.entity("identity").to(["read", "write", "delete"]),
16+
],
17+
}),
18+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2022",
4+
"module": "es2022",
5+
"moduleResolution": "bundler",
6+
"resolveJsonModule": true,
7+
"esModuleInterop": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"strict": true,
10+
"skipLibCheck": true,
11+
"paths": {
12+
"$amplify/*": [
13+
"../.amplify/generated/*"
14+
]
15+
}
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "dots-in-name",
3+
"version": "1.0.0",
4+
"main": "index.js"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# amplify
2+
node_modules
3+
.amplify
4+
amplify_outputs*
5+
amplifyconfiguration*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PreSignUpTriggerHandler } from "aws-lambda";
2+
import { preSignUpTriggerHandler } from "infra-common";
3+
4+
export const handler: PreSignUpTriggerHandler = preSignUpTriggerHandler;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineAuth, defineFunction } from "@aws-amplify/backend";
2+
3+
export const preSignUp = defineFunction({
4+
name: "pre-sign-up",
5+
entry: "./pre-sign-up-handler.ts",
6+
});
7+
8+
/**
9+
* Define and configure your auth resource
10+
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
11+
*/
12+
export const auth = defineAuth({
13+
loginWith: {
14+
email: true,
15+
},
16+
triggers: {
17+
preSignUp,
18+
},
19+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { defineBackend } from "@aws-amplify/backend";
2+
import * as s3 from "aws-cdk-lib/aws-s3";
3+
import { auth } from "./auth/resource";
4+
import { storage } from "./storage/resource";
5+
6+
/**
7+
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
8+
*/
9+
const backend = defineBackend({
10+
auth,
11+
storage,
12+
});
13+
14+
// custom storage configurations
15+
const s3Bucket = backend.storage.resources.bucket;
16+
const cfnBucket = s3Bucket.node.defaultChild as s3.CfnBucket;
17+
18+
cfnBucket.accelerateConfiguration = {
19+
accelerationStatus: "Enabled",
20+
};
21+
22+
// required to add the metadata header, which amplify-backend does not support
23+
backend.storage.resources.cfnResources.cfnBucket.corsConfiguration = {
24+
corsRules: [
25+
{
26+
allowedHeaders: ["*"],
27+
allowedMethods: ["GET", "HEAD", "PUT", "POST", "DELETE"],
28+
allowedOrigins: ["*"],
29+
exposedHeaders: [
30+
"x-amz-server-side-encryption",
31+
"x-amz-request-id",
32+
"x-amz-id-2",
33+
"ETag",
34+
"x-amz-meta-description",
35+
],
36+
maxAge: 3000,
37+
},
38+
],
39+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineStorage } from "@aws-amplify/backend";
2+
3+
export const storage = defineStorage({
4+
name: "Storage Integ Test main",
5+
access: (allow) => ({
6+
"public/*": [
7+
allow.guest.to(["read", "write", "delete"]),
8+
allow.authenticated.to(["read", "delete", "write"]),
9+
],
10+
"protected/{entity_id}/*": [
11+
allow.authenticated.to(["read"]),
12+
allow.entity("identity").to(["read", "write", "delete"]),
13+
],
14+
"private/{entity_id}/*": [
15+
allow.entity("identity").to(["read", "write", "delete"]),
16+
],
17+
}),
18+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2022",
4+
"module": "es2022",
5+
"moduleResolution": "bundler",
6+
"resolveJsonModule": true,
7+
"esModuleInterop": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"strict": true,
10+
"skipLibCheck": true,
11+
"paths": {
12+
"$amplify/*": [
13+
"../.amplify/generated/*"
14+
]
15+
}
16+
}
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "main",
3+
"version": "1.0.0",
4+
"main": "index.js"
5+
}

0 commit comments

Comments
 (0)