forked from aws-amplify/amplify-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(infra): analytics integ test gen 2 backend (aws-amplify#5104)
- Loading branch information
1 parent
1a40396
commit 8a9bee8
Showing
43 changed files
with
672 additions
and
16 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/analytics/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; |
19 changes: 19 additions & 0 deletions
19
infra-gen2/backends/analytics/main/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, | ||
}, | ||
}); |
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,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); |
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" | ||
} |
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": "analytics-main", | ||
"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,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! | ||
} |
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/analytics/no-unauth-access/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/analytics/no-unauth-access/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, | ||
}, | ||
}); |
26 changes: 26 additions & 0 deletions
26
infra-gen2/backends/analytics/no-unauth-access/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,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); |
3 changes: 3 additions & 0 deletions
3
infra-gen2/backends/analytics/no-unauth-access/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" | ||
} |
17 changes: 17 additions & 0 deletions
17
infra-gen2/backends/analytics/no-unauth-access/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": "no-unauth-access", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |
5 changes: 5 additions & 0 deletions
5
infra-gen2/backends/analytics/no-unauth-identities/.gitignore
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/analytics/no-unauth-identities/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/analytics/no-unauth-identities/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, | ||
}, | ||
}); |
31 changes: 31 additions & 0 deletions
31
infra-gen2/backends/analytics/no-unauth-identities/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,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); |
3 changes: 3 additions & 0 deletions
3
infra-gen2/backends/analytics/no-unauth-identities/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" | ||
} |
17 changes: 17 additions & 0 deletions
17
infra-gen2/backends/analytics/no-unauth-identities/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/*" | ||
] | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
infra-gen2/backends/analytics/no-unauth-identities/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,5 @@ | ||
{ | ||
"name": "no-unauth-identities", | ||
"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,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. |
47 changes: 47 additions & 0 deletions
47
infra-gen2/infra-common/src/analytics-extensions/analytics-extensions.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,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: [], | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.