Skip to content

Commit 29bfad7

Browse files
committed
feat: Add mis build to the data factory
1 parent 38d6986 commit 29bfad7

File tree

6 files changed

+144
-39
lines changed

6 files changed

+144
-39
lines changed

.changeset/rare-kiwis-live.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@aws-amplify/backend': patch
3+
'@aws-amplify/backend-data': patch
4+
'@aws-amplify/model-generator': patch
5+
---
6+
7+
feat: Add mis build to S3 from the data construct factory

package-lock.json

Lines changed: 24 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/backend-data/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"@aws-amplify/backend-output-storage": "^1.1.3",
3232
"@aws-amplify/backend-output-schemas": "^1.4.0",
3333
"@aws-amplify/data-construct": "^1.10.1",
34-
"@aws-amplify/plugin-types": "^1.4.0",
35-
"@aws-amplify/data-schema-types": "^1.2.0"
34+
"@aws-amplify/data-schema-types": "^1.2.0",
35+
"@aws-amplify/graphql-generator": "^0.5.1",
36+
"@aws-amplify/plugin-types": "^1.4.0"
3637
}
3738
}

packages/backend-data/src/app_sync_policy_generator.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export class AppSyncPolicyGenerator {
1414
/**
1515
* Initialize with the GraphqlAPI that the policies will be scoped to
1616
*/
17-
constructor(private readonly graphqlApi: IGraphqlApi) {
17+
constructor(
18+
private readonly graphqlApi: IGraphqlApi,
19+
private readonly modelIntrospectionSchemaArn?: string
20+
) {
1821
this.stack = Stack.of(graphqlApi);
1922
}
2023
/**
@@ -29,13 +32,25 @@ export class AppSyncPolicyGenerator {
2932
.map((action) => actionToTypeMap[action])
3033
// convert Type to resourceName
3134
.map((type) => [this.graphqlApi.arn, 'types', type, '*'].join('/'));
32-
return new Policy(this.stack, `${this.policyPrefix}${this.policyCount++}`, {
33-
statements: [
35+
36+
const statements = [
37+
new PolicyStatement({
38+
actions: ['appsync:GraphQL'],
39+
resources,
40+
}),
41+
];
42+
43+
if (this.modelIntrospectionSchemaArn) {
44+
statements.push(
3445
new PolicyStatement({
35-
actions: ['appsync:GraphQL'],
36-
resources,
37-
}),
38-
],
46+
actions: ['s3:GetObject'],
47+
resources: [this.modelIntrospectionSchemaArn],
48+
})
49+
);
50+
}
51+
52+
return new Policy(this.stack, `${this.policyPrefix}${this.policyCount++}`, {
53+
statements,
3954
});
4055
}
4156
}

packages/backend-data/src/factory.test.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ const createConstructContainerWithUserPoolAuthRegistered = (
8585
authenticatedUserIamRole: new Role(stack, 'testAuthRole', {
8686
assumedBy: new ServicePrincipal('test.amazon.com'),
8787
}),
88-
identityPoolId: 'identityPoolId',
8988
cfnResources: {
9089
cfnUserPool: new CfnUserPool(stack, 'CfnUserPool', {}),
9190
cfnUserPoolClient: new CfnUserPoolClient(stack, 'CfnUserPoolClient', {
@@ -101,6 +100,7 @@ const createConstructContainerWithUserPoolAuthRegistered = (
101100
),
102101
},
103102
groups: {},
103+
identityPoolId: 'identityPool',
104104
},
105105
}),
106106
});
@@ -567,6 +567,23 @@ void describe('DataFactory', () => {
567567
},
568568
],
569569
},
570+
{
571+
Action: 's3:GetObject',
572+
Resource: {
573+
'Fn::Join': [
574+
'',
575+
[
576+
{
577+
'Fn::GetAtt': [
578+
'modelIntrospectionSchemaBucketF566B665',
579+
'Arn',
580+
],
581+
},
582+
'/modelIntrospectionSchema.json',
583+
],
584+
],
585+
},
586+
},
570587
],
571588
},
572589
Roles: [
@@ -675,6 +692,23 @@ void describe('DataFactory', () => {
675692
],
676693
},
677694
},
695+
{
696+
Action: 's3:GetObject',
697+
Resource: {
698+
'Fn::Join': [
699+
'',
700+
[
701+
{
702+
'Fn::GetAtt': [
703+
'modelIntrospectionSchemaBucketF566B665',
704+
'Arn',
705+
],
706+
},
707+
'/modelIntrospectionSchema.json',
708+
],
709+
],
710+
},
711+
},
678712
],
679713
},
680714
Roles: [
@@ -701,6 +735,23 @@ void describe('DataFactory', () => {
701735
],
702736
},
703737
},
738+
{
739+
Action: 's3:GetObject',
740+
Resource: {
741+
'Fn::Join': [
742+
'',
743+
[
744+
{
745+
'Fn::GetAtt': [
746+
'modelIntrospectionSchemaBucketF566B665',
747+
'Arn',
748+
],
749+
},
750+
'/modelIntrospectionSchema.json',
751+
],
752+
],
753+
},
754+
},
704755
],
705756
},
706757
Roles: [

0 commit comments

Comments
 (0)