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

chore(infra): analytics integ test gen 2 backend #5104

Merged
merged 81 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
8cc5c7d
feat(core): add AmplifyOutputs types based on the CLI Gen2 client con…
NikaHsn May 22, 2024
c478e98
chore: map AmplifyConfig to AmplifyOutputs (#4935)
Jordan-Nelson May 30, 2024
bbbab89
chore: support multiple graphql or rest APIs (#4982)
Jordan-Nelson Jun 5, 2024
6671f1f
chore: update gen2 version and config mapping tests (#5010)
Jordan-Nelson Jun 13, 2024
1f1552b
chore: supporting missing auth config options (#5011)
Jordan-Nelson Jun 13, 2024
ca2cc29
chore: map null passwordSettings to null passwordPolicy (#5024)
Jordan-Nelson Jun 14, 2024
9ab3ad9
chore(core): updated asyncConfig to use AmplifyOutputs (#4995)
tyllark Jun 14, 2024
56f4980
chore: fix oauth outputs (#5028)
Jordan-Nelson Jun 17, 2024
ea5d25a
chore(infra-gen2): Gen 2 infra (#5026)
Equartey Jun 18, 2024
0c48b66
chore(infra): gen 2 api rename (#5040)
Equartey Jun 20, 2024
161f73a
chore(infra): Add verbose flag to deploy step (#5042)
Equartey Jun 24, 2024
3bb5550
chore: init commit
khatruong2009 Jun 25, 2024
924d1a3
Merge branch 'feat/config-gen2' into chore/gen2-storage-integ
khatruong2009 Jun 25, 2024
05429e8
chore: update configure apis to use AmplifyOutputs instead of Amplify…
NikaHsn Jun 25, 2024
30596b9
chore: added more settings to the s3 buckets
khatruong2009 Jun 25, 2024
a1502c5
Merge branch 'feat/config-gen2' into chore/gen2-storage-integ
khatruong2009 Jun 25, 2024
e8c0f95
chore(core): add validation checks for AmplifyOutputs Json deserializ…
NikaHsn Jun 26, 2024
dddcf36
Merge branch 'feat/config-gen2' into chore/gen2-storage-integ
khatruong2009 Jun 26, 2024
e74969b
chore: fix bucket names and remove data
khatruong2009 Jun 26, 2024
778796d
chore: update storage tests and backend
khatruong2009 Jul 1, 2024
29ec77c
Merge branch 'main' into chore/gen2-storage-integ
khatruong2009 Jul 1, 2024
4da74ba
chore: reupdated deploy_gen2.dart script with storage backends
khatruong2009 Jul 1, 2024
516dabd
chore: correct name of main environment in deploy script
khatruong2009 Jul 1, 2024
31659d1
chore: analytics integ test backend init commit
khatruong2009 Jul 1, 2024
e3f8469
chore: add pre sign up trigger
khatruong2009 Jul 1, 2024
85f4b4d
chore: add analytics to deploy script and configure
khatruong2009 Jul 1, 2024
ddc9e7e
chore: add data back in
khatruong2009 Jul 1, 2024
65b19d5
chore: add dots to bucket name and revert tests
khatruong2009 Jul 10, 2024
9a38480
Merge branch 'main' into chore/gen2-storage-integ
khatruong2009 Jul 16, 2024
df12662
Merge branch 'main' into chore/gen2-storage-integ
khatruong2009 Jul 17, 2024
f49e859
chore: update pull test backend file
khatruong2009 Jul 17, 2024
a348147
chore: pull amplify_outputs instead of amplifyconfiguration
khatruong2009 Jul 18, 2024
50e1bda
chore: fixed path to outputs file
khatruong2009 Jul 18, 2024
c9b3bf6
Merge branch 'main' into chore/gen2-storage-integ
khatruong2009 Jul 18, 2024
56288a2
chore: adding a comment to trigger integ tests
khatruong2009 Jul 18, 2024
1b4a017
Revert "chore: adding a comment to trigger integ tests"
khatruong2009 Jul 18, 2024
26a5e9e
Reapply "chore: adding a comment to trigger integ tests"
khatruong2009 Jul 18, 2024
6595465
Revert "Reapply "chore: adding a comment to trigger integ tests""
khatruong2009 Jul 19, 2024
d4759b5
Merge branch 'main' into chore/gen2-storage-integ
khatruong2009 Jul 19, 2024
4ebb37c
Merge branch 'main' into chore/gen2-storage-integ
khatruong2009 Jul 22, 2024
f82e3ce
chore: added cors policies to fix web metadata issue
khatruong2009 Jul 23, 2024
dc4b775
chore: code cleanup
khatruong2009 Jul 23, 2024
74a3165
chore: remove unnecessary ignore statement
khatruong2009 Jul 23, 2024
0bbf80c
chore: remove unnecessary data backend files
khatruong2009 Jul 23, 2024
808c935
chore: restore package-lock from main and run npm i
khatruong2009 Jul 24, 2024
f983a7c
chore: upgrade amplify backend in dots-in-name package
khatruong2009 Jul 24, 2024
6c99f1c
chore: removed unnecessary dependency in dots package.json
khatruong2009 Jul 24, 2024
2ceecc9
chore: remove unnecessary package-lock file in backends/main folder
khatruong2009 Jul 24, 2024
280aadd
chore: fix package.json files in backend/analytics directories
khatruong2009 Jul 24, 2024
4dea6af
Merge branch 'chore/gen2-storage-integ' into chore/gen2-analytics-integ
khatruong2009 Jul 24, 2024
67ccba7
Update infra-gen2/backends/storage/dots-in-name/amplify/backend.ts
khatruong2009 Jul 25, 2024
da6fcae
chore: delete common.ts since randomBucketName method isn't being used
khatruong2009 Jul 25, 2024
e595e2d
Merge branch 'chore/gen2-storage-integ' into chore/gen2-analytics-integ
khatruong2009 Jul 25, 2024
01c0335
Merge branch 'main' into chore/gen2-analytics-integ
khatruong2009 Jul 25, 2024
14ab550
chore: correct the name of the analytics stack to the name of the bac…
khatruong2009 Jul 25, 2024
9029a4b
chore: add schema to infra-common
khatruong2009 Jul 25, 2024
d1ae903
chore: add custom cdk items
khatruong2009 Jul 26, 2024
3df9a08
Merge branch 'main' into chore/gen2-analytics-integ
khatruong2009 Jul 29, 2024
847820e
Merge branch 'main' into chore/gen2-analytics-integ
khatruong2009 Jul 30, 2024
7c18ca8
chore: remove data from amplify set up and add to CDK setup
khatruong2009 Jul 30, 2024
0cc7301
chore: add name to add analytics extension
khatruong2009 Jul 30, 2024
e4c4136
chore: fix location of expiration.ts
khatruong2009 Jul 30, 2024
9949fa1
chore: test move all CDK stuff into backend.ts
khatruong2009 Aug 2, 2024
3fb23fd
chore: delete unnecessary backend.kinesis-consumer.ts file
khatruong2009 Aug 7, 2024
2da86af
chore: remove unnecessary data resource.ts files from non main enviro…
khatruong2009 Aug 7, 2024
6f92e9e
Merge branch 'main' into chore/gen2-analytics-integ
khatruong2009 Aug 7, 2024
ce31198
chore: code cleanup
khatruong2009 Aug 7, 2024
ceeb98c
chore: ios utilities
khatruong2009 Aug 7, 2024
2a2968b
chore: add version number to example app
khatruong2009 Aug 7, 2024
12f2fbe
chore: update amplify outputs imports
khatruong2009 Aug 8, 2024
f6d71e0
chore: update pull_test_backend.sh
khatruong2009 Aug 8, 2024
91549ba
Merge branch 'main' into chore/gen2-analytics-integ
khatruong2009 Aug 8, 2024
688dc0b
chore: test amplifyConfig variable renaming
khatruong2009 Aug 8, 2024
0342643
chore: make print statement a safeprint statement in example app
khatruong2009 Aug 8, 2024
0261311
chore: run dart format
khatruong2009 Aug 8, 2024
7042f40
chore: get the pinpoint app ID from specifically the main environment
khatruong2009 Aug 8, 2024
0e02ce2
chore: test casting environment to a map
khatruong2009 Aug 8, 2024
eeb1c1e
chore: run dart format
khatruong2009 Aug 9, 2024
2063e91
chore: add ignore dynamic calls to the whole file
khatruong2009 Aug 9, 2024
b1c0e2e
chore: remove commented code
khatruong2009 Aug 13, 2024
f8a656c
Merge branch 'main' into chore/gen2-analytics-integ
khatruong2009 Aug 13, 2024
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
5 changes: 5 additions & 0 deletions infra-gen2/backends/analytics/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amplify
node_modules
.amplify
amplify_outputs*
amplifyconfiguration*
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 infra-gen2/backends/analytics/main/amplify/auth/resource.ts
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,
},
});
28 changes: 28 additions & 0 deletions infra-gen2/backends/analytics/main/amplify/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineBackend } from "@aws-amplify/backend";
import { addAnalyticsExtensions } from "infra-common";
import { auth } from "./auth/resource";

/**
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
*/

const backend = defineBackend({
auth,
});

const pinpointRole = backend.auth.resources.authenticatedUserIamRole;
const unauthPinpointRole = backend.auth.resources.unauthenticatedUserIamRole;

const resources = backend.auth.resources;
const { userPool, cfnResources } = resources;
const { stack } = userPool;

const customOutputs = addAnalyticsExtensions({
name: "analytics-main",
stack: stack,
authenticatedRole: pinpointRole,
unauthenticatedRole: unauthPinpointRole,
});

// patch the custom Pinpoint resource to the expected output configuration
backend.addOutput(customOutputs);
3 changes: 3 additions & 0 deletions infra-gen2/backends/analytics/main/amplify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
17 changes: 17 additions & 0 deletions infra-gen2/backends/analytics/main/amplify/tsconfig.json
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/*"
]
}
}
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/analytics/main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "analytics-main",
"version": "1.0.0",
"main": "index.js"
}
22 changes: 22 additions & 0 deletions infra-gen2/backends/analytics/main/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type Query {
getRecord(id: ID!): Record @aws_api_key
listRecords: [Record] @aws_api_key
}

type Mutation {
createRecord(input: RecordInput!): Record @aws_api_key
}

type Subscription {
onCreateRecord: Record @aws_subscribe(mutations: ["createRecord"])
}

type Record {
id: ID!
payload: String!
}

input RecordInput {
id: ID!
payload: String!
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/analytics/no-unauth-access/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amplify
node_modules
.amplify
amplify_outputs*
amplifyconfiguration*
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;
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,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { defineBackend } from "@aws-amplify/backend";
import { addAnalyticsExtensions } from "infra-common";
import { auth } from "./auth/resource";

/**
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
*/

const backend = defineBackend({
auth,
});

const pinpointRole = backend.auth.resources.authenticatedUserIamRole;

const resources = backend.auth.resources;
const { userPool, cfnResources } = resources;
const { stack } = userPool;

const customOutputs = addAnalyticsExtensions({
name: "analytics-main",
stack: stack,
authenticatedRole: pinpointRole,
});

// patch the custom Pinpoint resource to the expected output configuration
backend.addOutput(customOutputs);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
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/*"
]
}
}
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/analytics/no-unauth-access/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "no-unauth-access",
"version": "1.0.0",
"main": "index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amplify
node_modules
.amplify
amplify_outputs*
amplifyconfiguration*
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;
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,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineBackend } from "@aws-amplify/backend";
import { addAnalyticsExtensions } from "infra-common";
import { auth } from "./auth/resource";

/**
* @see https://docs.amplify.aws/react/build-a-backend/ to add storage, functions, and more
*/

const backend = defineBackend({
auth,
});

const { cfnIdentityPool } = backend.auth.resources.cfnResources;
cfnIdentityPool.allowUnauthenticatedIdentities = false;

const pinpointRole = backend.auth.resources.authenticatedUserIamRole;
const unauthPinpointRole = backend.auth.resources.unauthenticatedUserIamRole;

const resources = backend.auth.resources;
const { userPool, cfnResources } = resources;
const { stack } = userPool;

const customOutputs = addAnalyticsExtensions({
name: "analytics-main",
stack: stack,
authenticatedRole: pinpointRole,
unauthenticatedRole: unauthPinpointRole,
});

// patch the custom Pinpoint resource to the expected output configuration
backend.addOutput(customOutputs);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
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/*"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "no-unauth-identities",
"version": "1.0.0",
"main": "index.js"
}
9 changes: 9 additions & 0 deletions infra-gen2/infra-common/src/analytics-extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# analytics-extensions

This directory contains extensions for the analytics backend, including:

- Setting up Pinpoint
- Setting up a Kinesis Data stream and configure Pinpoint to stream events to it
- Create a Records table to store events from the Kinesis stream
- Create the GraphQL API to which we will publish Kinesis records
- Create the Kinesis consumer Lambda which will capture events from the Kinesis Data Stream and forward them to AppSync.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { BackendBase } from "@aws-amplify/backend";
import { Stack } from "aws-cdk-lib";
import { IRole } from "aws-cdk-lib/aws-iam";
import { createAppSyncAPI } from "./data";
import { createKinesisStream } from "./kinesis";
import { createPinpointApp } from "./pinpoint";

type AmplifyOutputs = Parameters<BackendBase["addOutput"]>[0];

export const addAnalyticsExtensions = ({
name,
stack,
authenticatedRole,
unauthenticatedRole,
}: {
name: string;
stack: Stack;
authenticatedRole: IRole;
unauthenticatedRole?: IRole;
}): AmplifyOutputs => {
const pinpointApp = createPinpointApp(
name,
stack,
authenticatedRole,
unauthenticatedRole
);

const kinesisStream = createKinesisStream(name, stack, pinpointApp);

const graphQLApi = createAppSyncAPI(name, stack, kinesisStream);

return {
analytics: {
amazon_pinpoint: {
app_id: pinpointApp.ref,
aws_region: Stack.of(pinpointApp).region,
},
},
data: {
aws_region: stack.region,
url: graphQLApi.graphqlUrl,
api_key: graphQLApi.apiKey,
default_authorization_type: "API_KEY",
authorization_types: [],
},
};
};
Loading
Loading