-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* custom examples
- Loading branch information
Showing
6 changed files
with
434 additions
and
5 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
76 changes: 76 additions & 0 deletions
76
src/pages/gen2/build-a-backend/add-aws-services/analytics/index.mdx
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,76 @@ | ||
export const meta = { | ||
title: 'Analytics', | ||
description: 'Learn how to set Analytics resource powered by Pinpoint' | ||
}; | ||
|
||
export function getStaticProps(context) { | ||
return { | ||
props: { | ||
meta | ||
} | ||
}; | ||
} | ||
|
||
<Callout warning> | ||
|
||
**Under active development:** The `addOutput` method for Amplify (Gen 2) is under active development. The experience may change between versions of `@aws-amplify/backend`. Try it out and provide feedback at https://github.com/aws-amplify/amplify-backend/issues/new/choose | ||
|
||
</Callout> | ||
|
||
Amplify enables you to collect analytics data for your app. The Analytics category uses Amazon Cognito Identity pools to _identify_ users in your app. | ||
The following is an example utilizing the [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) to create the an Analytics resource powered by [Amazon Pinpoint](https://aws.amazon.com/pinpoint/). | ||
|
||
```ts title="amplify/backend.ts" | ||
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam"; | ||
import { CfnApp } from "aws-cdk-lib/aws-pinpoint"; | ||
|
||
const backend = defineBackend({ | ||
auth, | ||
data, | ||
// additional resources | ||
}); | ||
|
||
const analyticsStack = backend.createStack("analytics-stack"); | ||
|
||
// create a Pinpoint app | ||
const pinpoint = new CfnApp(analyticsStack, "Pinpoint", { | ||
name: "myPinpointApp", | ||
}); | ||
|
||
// create an IAM policy to allow interacting with Pinpoint | ||
const pinpointPolicy = new Policy(analyticsStack, "PinpointPolicy", { | ||
policyName: "PinpointPolicy", | ||
statements: [ | ||
new PolicyStatement({ | ||
actions: ["mobiletargeting:UpdateEndpoint", "mobiletargeting:PutEvents"], | ||
resources: [pinpoint.attrArn + "/*"], | ||
}), | ||
], | ||
}); | ||
|
||
// apply the policy to the authenticated and unauthenticated roles | ||
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(pinpointPolicy); | ||
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(pinpointPolicy); | ||
|
||
// patch the custom Pinpoint resource to the expected output configuration | ||
backend.addOutput({ | ||
Analytics: { | ||
AWSPinpoint: { | ||
appId: pinpoint.ref, | ||
region: Stack.of(pinpoint).region, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
### Initialize Analytics | ||
|
||
To initialize Analytics you need to configure Amplify with `Amplify.configure()` | ||
|
||
### Working with Analytics | ||
|
||
Refer to the [Analytics documentation](/react/build-a-backend/more-features/analytics/) to learn how to track events and user sessions in your app. | ||
|
||
### References | ||
|
||
[Amazon Pinpoint Construct Library](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_pinpoint-readme.html) |
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
97 changes: 97 additions & 0 deletions
97
src/pages/gen2/build-a-backend/add-aws-services/geo/index.mdx
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,97 @@ | ||
export const meta = { | ||
title: 'Geo', | ||
description: 'Learn how to set up Geo resource powered by Amazon Location Services.' | ||
}; | ||
|
||
export function getStaticProps(context) { | ||
return { | ||
props: { | ||
meta | ||
} | ||
}; | ||
} | ||
|
||
<Callout warning> | ||
|
||
**Under active development:** The `addOutput` method for Amplify (Gen 2) is under active development. The experience may change between versions of `@aws-amplify/backend`. Try it out and provide feedback at https://github.com/aws-amplify/amplify-backend/issues/new/choose | ||
|
||
</Callout> | ||
|
||
Amplify provides APIs and map UI components for maps and location search for your web apps. The following is an example utilizing the [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) to create a Geo resource powered by [Amazon Location Services](https://aws.amazon.com/location/). | ||
|
||
```ts title="amplify/backend.ts" | ||
import { CfnMap } from "aws-cdk-lib/aws-location"; | ||
|
||
const backend = defineBackend({ | ||
auth, | ||
data, | ||
// additional resources | ||
}); | ||
|
||
const geoStack = backend.createStack("geo-stack"); | ||
|
||
// create a location services map | ||
const map = new CfnMap(geoStack, "Map", { | ||
mapName: "myMap", | ||
description: "Map", | ||
configuration: { | ||
style: "VectorEsriNavigation", | ||
}, | ||
pricingPlan: "RequestBasedUsage", | ||
tags: [ | ||
{ | ||
key: "name", | ||
value: "myMap", | ||
}, | ||
], | ||
}); | ||
|
||
// create an IAM policy to allow interacting with geo resource | ||
const myGeoPolicy = new Policy(geoStack, "AuthenticatedUserIamRolePolicy", { | ||
policyName: "GeoPolicy", | ||
statements: [ | ||
new PolicyStatement({ | ||
actions: [ | ||
"geo:GetMapTile", | ||
"geo:GetMapSprites", | ||
"geo:GetMapGlyphs", | ||
"geo:GetMapStyleDescriptor", | ||
], | ||
resources: [map.attrArn], | ||
}), | ||
], | ||
}); | ||
|
||
// apply the policy to the authenticated and unauthenticated roles | ||
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy); | ||
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy); | ||
|
||
// patch the custom map resource to the expected output configuration | ||
backend.addOutput({ | ||
geo: { | ||
amazon_location_service: { | ||
region: Stack.of(geoStack).region, | ||
maps: { | ||
items: { | ||
[map.mapName]: { | ||
style: "VectorEsriNavigation", | ||
}, | ||
}, | ||
default: map.mapName, | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
### Initialize Geo | ||
|
||
To initialize Geo you need to configure Amplify with `Amplify.configure()` | ||
|
||
### Working with Maps | ||
|
||
To display a map in your React app, you can use the [Amplify React MapView component](https://ui.docs.amplify.aws/react/components/geo) or the [MapLibre GL](https://github.com/maplibre/maplibre-gl-js) with `maplibre-gl-js-amplify` libraries are required. Refer to the [Amplify Geo documentation](/react/build-a-backend/more-features/geo/maps/) for more information. | ||
|
||
### References | ||
|
||
[Location Construct Library](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_location-readme.html) |
136 changes: 136 additions & 0 deletions
136
src/pages/gen2/build-a-backend/add-aws-services/in-app-messaging/index.mdx
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,136 @@ | ||
export const meta = { | ||
title: 'In-App Messaging', | ||
description: 'Learn how to set up In-App Messaging resource powered by Pinpoint' | ||
}; | ||
|
||
export function getStaticProps(context) { | ||
return { | ||
props: { | ||
meta | ||
} | ||
}; | ||
} | ||
|
||
<Callout warning> | ||
|
||
**Under active development:** The `addOutput` method for Amplify (Gen 2) is under active development. The experience may change between versions of `@aws-amplify/backend`. Try it out and provide feedback at https://github.com/aws-amplify/amplify-backend/issues/new/choose | ||
|
||
</Callout> | ||
|
||
Amplify allows interacting with In-App Messaging APIs, which enables you to send messages to your app users. In-App Messaging is a powerful tool to engage with your users and provide them with relevant information. The following is an example utilizing the [AWS Cloud Development Kit (AWS CDK)](https://docs.aws.amazon.com/cdk/latest/guide/home.html) to create the In-App Messaging resource powered by [Amazon Pinpoint](https://aws.amazon.com/pinpoint/). | ||
|
||
```ts title="amplify/backend.ts" | ||
import { | ||
CfnApp, | ||
CfnInAppTemplate, | ||
CfnCampaign, | ||
CfnSegment, | ||
} from "aws-cdk-lib/aws-pinpoint"; | ||
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam"; | ||
import { Stack } from "aws-cdk-lib"; | ||
|
||
const backend = defineBackend({ | ||
auth, | ||
data, | ||
// additional resources | ||
}); | ||
|
||
const inAppMessagingStack = backend.createStack("inAppMessaging-stack"); | ||
|
||
// create a Pinpoint app | ||
const pinpoint = new CfnApp(inAppMessagingStack, "Pinpoint", { | ||
name: "myPinpointApp", | ||
}); | ||
|
||
// create a segment | ||
const mySegment = new CfnSegment(inAppMessagingStack, "Segment", { | ||
applicationId: pinpoint.ref, | ||
name: "mySegment", | ||
}); | ||
|
||
// create a campaign with event and in-app message template | ||
new CfnCampaign(inAppMessagingStack, "MyCampaign", { | ||
applicationId: pinpoint.ref, | ||
name: "MyCampaign", | ||
segmentId: mySegment.attrSegmentId, | ||
schedule: { | ||
// ensure the start and end time are in the future | ||
startTime: "2024-02-23T14:39:34Z", | ||
endTime: "2024-02-29T14:32:40Z", | ||
frequency: "IN_APP_EVENT", | ||
eventFilter: { | ||
dimensions: { | ||
eventType: { | ||
dimensionType: "INCLUSIVE", | ||
values: ["PURCHASE"], | ||
}, | ||
}, | ||
filterType: "ENDPOINT", | ||
}, | ||
}, | ||
|
||
messageConfiguration: { | ||
inAppMessage: { | ||
layout: "TOP_BANNER", | ||
content: [ | ||
{ | ||
// define the content of the in-app message | ||
bodyConfig: { | ||
alignment: "CENTER", | ||
body: "This is an example in-app message.", | ||
textColor: "#FFFFFF", | ||
}, | ||
backgroundColor: "#000000", | ||
headerConfig: { | ||
alignment: "CENTER", | ||
header: "Welcome!", | ||
textColor: "#FFFFFF", | ||
}, | ||
// optionally, define buttons, images, etc. | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
//create an IAM policy to allow interacting with Pinpoint in-app messaging | ||
const pinpointPolicy = new Policy(inAppMessagingStack, "PinpointPolicy", { | ||
policyName: "PinpointPolicy", | ||
statements: [ | ||
new PolicyStatement({ | ||
actions: ["mobiletargeting:GetInAppMessages"], | ||
resources: [pinpoint.attrArn + "/*"], | ||
}), | ||
], | ||
}); | ||
|
||
// apply the policy to the authenticated and unauthenticated roles | ||
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(pinpointPolicy); | ||
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(pinpointPolicy); | ||
|
||
// patch the custom Pinpoint resource to the expected output configuration | ||
backend.addOutput({ | ||
Notifications: { | ||
InAppMessaging: { | ||
AWSPinpoint: { | ||
appId: pinpoint.ref, | ||
region: Stack.of(pinpoint).region, | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
|
||
### Initialize In-App Messaging | ||
|
||
To initialize In-App Messaging you need to configure Amplify with `Amplify.configure()` | ||
|
||
|
||
### Working with In-App Messaging | ||
|
||
Refer to the [Amplify In-App Messaging documentation](/react/build-a-backend/more-features/in-app-messaging/) to learn how to send in-app messages to your app users. | ||
|
||
### References | ||
|
||
[Amazon Pinpoint Construct Library](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_pinpoint-readme.html) |
Oops, something went wrong.