Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ __pycache__/
#amplify
.amplify/
amplify/
#keep amplify gen2 backend projects
!**/androidTest/backend/amplify/
build/
dist/
node_modules/
Expand Down
7 changes: 0 additions & 7 deletions appsync/aws-sdk-appsync-amplify/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ group = properties["POM_GROUP"].toString()

android {
namespace = "com.amazonaws.sdk.appsync.amplify"
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

testOptions {
execution = "ANDROIDX_TEST_ORCHESTRATOR"
}
}

dependencies {
Expand Down
13 changes: 13 additions & 0 deletions appsync/aws-sdk-appsync-events/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,17 @@ dependencies {
testImplementation(libs.test.kotest.assertions)
testImplementation(libs.test.kotest.assertions.json)
testImplementation(libs.test.mockwebserver)
testImplementation(libs.test.turbine)

androidTestApi(project(":aws-sdk-appsync-amplify"))
androidTestImplementation(project(":aws-auth-cognito"))
androidTestImplementation(project(":core-kotlin"))
androidTestImplementation(project(":testutils"))
androidTestImplementation(libs.test.androidx.runner)
androidTestImplementation(libs.test.androidx.junit)
androidTestImplementation(libs.test.kotlin.coroutines)
androidTestImplementation(libs.test.kotest.assertions)
androidTestImplementation(libs.test.turbine)

androidTestUtil(libs.test.androidx.orchestrator)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws.sdk.appsync.events.test">

<uses-permission android:name="android.permission.INTERNET" />
</manifest>
21 changes: 21 additions & 0 deletions appsync/aws-sdk-appsync-events/src/androidTest/backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## AWS Amplify + AWS AppSync Events Template

## Getting Started

1. Setup AWS Account with Amplify

https://docs.amplify.aws/android/start/account-setup/

2. Install dependencies:

```bash
npm install
```

3. Deploy Sandbox

```bash
npx ampx sandbox
```

4. Make note of the amplify_outputs.json file that was generated. You will need to copy this file to the test project.
20 changes: 20 additions & 0 deletions appsync/aws-sdk-appsync-events/src/androidTest/backend/amplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 1
backend:
phases:
build:
commands:
- npm ci
- npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
phases:
build:
commands:
- mkdir ./dist && touch ./dist/index.html
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
- .npm/**/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineAuth } from '@aws-amplify/backend';

/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/
export const auth = defineAuth({
loginWith: {
email: true,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { defineBackend } from '@aws-amplify/backend'
import { auth } from './auth/resource'
import {
AuthorizationType,
CfnApi,
CfnChannelNamespace,
CfnApiKey,
} from 'aws-cdk-lib/aws-appsync'
import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam'

const backend = defineBackend({ auth })

const customResources = backend.createStack('custom-resources-appsync-events')

const cfnEventAPI = new CfnApi(customResources, 'cfnEventAPI', {
name: 'appsync-events-integration-tests',
eventConfig: {
authProviders: [
{ authType: AuthorizationType.API_KEY },
{ authType: AuthorizationType.IAM },
{
authType: AuthorizationType.USER_POOL,
cognitoConfig: {
awsRegion: customResources.region,
userPoolId: backend.auth.resources.userPool.userPoolId,
},
}
],
connectionAuthModes: [
{ authType: AuthorizationType.API_KEY },
{ authType: AuthorizationType.IAM },
{ authType: AuthorizationType.USER_POOL }
],
defaultPublishAuthModes: [
{ authType: AuthorizationType.API_KEY },
{ authType: AuthorizationType.IAM },
{ authType: AuthorizationType.USER_POOL }
],
defaultSubscribeAuthModes: [
{ authType: AuthorizationType.API_KEY },
{ authType: AuthorizationType.IAM },
{ authType: AuthorizationType.USER_POOL }
],
},
})

new CfnChannelNamespace(customResources, 'CfnEventsIntegrationTestsNamespace', {
apiId: cfnEventAPI.attrApiId,
name: 'default',
})

new CfnChannelNamespace(customResources, 'CfnEventsIntegrationTestsCustomNamespace', {
apiId: cfnEventAPI.attrApiId,
name: 'custom',
})

// attach a policy to the authenticated user role in our User Pool to grant access to the Event API:
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(
new Policy(customResources, 'AuthAppSyncEventPolicy', {
statements: [
new PolicyStatement({
actions: [
'appsync:EventConnect',
'appsync:EventSubscribe',
'appsync:EventPublish',
],
resources: [`${cfnEventAPI.attrApiArn}/*`, `${cfnEventAPI.attrApiArn}`],
}),
],
})
);

// Add the policy as an inline policy (not `addToPrincialPolicy`) to avoid circular deps
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(
new Policy(customResources, 'UnauthAppSyncEventPolicy', {
statements: [
new PolicyStatement({
actions: [
'appsync:EventConnect',
'appsync:EventPublish',
'appsync:EventSubscribe',
],
resources: [`${cfnEventAPI.attrApiArn}/*`, `${cfnEventAPI.attrApiArn}`],
}),
],
})
)

// Create an API key
const apiKey = new CfnApiKey(customResources, 'EventApiKey', {
apiId: cfnEventAPI.attrApiId,
description: 'API Key for Event API',
expires: Math.floor(Date.now() / 1000) + (37 * 24 * 60 * 60) // Set for 37 days
})

backend.addOutput({
custom: {
events: {
url: `https://${cfnEventAPI.getAtt('Dns.Http').toString()}/event`,
aws_region: customResources.region,
default_authorization_type: AuthorizationType.API_KEY,
api_key: apiKey.attrApiKey
},
},
})
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/*"
]
}
}
}
Loading