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

feat: Add lamda data client support #2224

Merged
merged 18 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
7 changes: 7 additions & 0 deletions .changeset/brave-cheetahs-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@aws-amplify/backend': minor
'@aws-amplify/backend-function': minor
'@aws-amplify/backend-data': patch
---

Add lambda data client
67 changes: 35 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions packages/backend-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-amplify/data-schema": "^1.0.0",
"@aws-amplify/data-schema": "^1.13.4",
"@aws-amplify/backend-platform-test-stubs": "^0.3.6",
"@aws-amplify/platform-core": "^1.2.0"
},
Expand All @@ -31,7 +31,8 @@
"@aws-amplify/backend-output-storage": "^1.1.3",
"@aws-amplify/backend-output-schemas": "^1.4.0",
"@aws-amplify/data-construct": "^1.10.1",
"@aws-amplify/plugin-types": "^1.4.0",
"@aws-amplify/data-schema-types": "^1.2.0"
"@aws-amplify/data-schema-types": "^1.2.0",
"@aws-amplify/graphql-generator": "^0.5.1",
"@aws-amplify/plugin-types": "^1.4.0"
}
}
29 changes: 22 additions & 7 deletions packages/backend-data/src/app_sync_policy_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export class AppSyncPolicyGenerator {
/**
* Initialize with the GraphqlAPI that the policies will be scoped to
*/
constructor(private readonly graphqlApi: IGraphqlApi) {
constructor(
private readonly graphqlApi: IGraphqlApi,
private readonly modelIntrospectionSchemaArn?: string
) {
this.stack = Stack.of(graphqlApi);
}
/**
Expand All @@ -29,13 +32,25 @@ export class AppSyncPolicyGenerator {
.map((action) => actionToTypeMap[action])
// convert Type to resourceName
.map((type) => [this.graphqlApi.arn, 'types', type, '*'].join('/'));
return new Policy(this.stack, `${this.policyPrefix}${this.policyCount++}`, {
statements: [

const statements = [
new PolicyStatement({
actions: ['appsync:GraphQL'],
resources,
}),
];

if (this.modelIntrospectionSchemaArn) {
statements.push(
new PolicyStatement({
actions: ['appsync:GraphQL'],
resources,
}),
],
actions: ['s3:GetObject'],
resources: [this.modelIntrospectionSchemaArn],
})
);
}

return new Policy(this.stack, `${this.policyPrefix}${this.policyCount++}`, {
statements,
});
}
}
Expand Down
53 changes: 52 additions & 1 deletion packages/backend-data/src/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const createConstructContainerWithUserPoolAuthRegistered = (
authenticatedUserIamRole: new Role(stack, 'testAuthRole', {
assumedBy: new ServicePrincipal('test.amazon.com'),
}),
identityPoolId: 'identityPoolId',
cfnResources: {
cfnUserPool: new CfnUserPool(stack, 'CfnUserPool', {}),
cfnUserPoolClient: new CfnUserPoolClient(stack, 'CfnUserPoolClient', {
Expand All @@ -101,6 +100,7 @@ const createConstructContainerWithUserPoolAuthRegistered = (
),
},
groups: {},
identityPoolId: 'identityPool',
},
}),
});
Expand Down Expand Up @@ -567,6 +567,23 @@ void describe('DataFactory', () => {
},
],
},
{
Action: 's3:GetObject',
Resource: {
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'modelIntrospectionSchemaBucketF566B665',
'Arn',
],
},
'/modelIntrospectionSchema.json',
],
],
},
},
],
},
Roles: [
Expand Down Expand Up @@ -675,6 +692,23 @@ void describe('DataFactory', () => {
],
},
},
{
Action: 's3:GetObject',
Resource: {
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'modelIntrospectionSchemaBucketF566B665',
'Arn',
],
},
'/modelIntrospectionSchema.json',
],
],
},
},
],
},
Roles: [
Expand All @@ -701,6 +735,23 @@ void describe('DataFactory', () => {
],
},
},
{
Action: 's3:GetObject',
Resource: {
'Fn::Join': [
'',
[
{
'Fn::GetAtt': [
'modelIntrospectionSchemaBucketF566B665',
'Arn',
],
},
'/modelIntrospectionSchema.json',
],
],
},
},
],
},
Roles: [
Expand Down
Loading
Loading