@@ -46,6 +46,10 @@ import {
46
46
FunctionSchemaAccess ,
47
47
JsResolver ,
48
48
} from '@aws-amplify/data-schema-types' ;
49
+ import { Bucket } from 'aws-cdk-lib/aws-s3' ;
50
+ import { BucketDeployment , Source } from 'aws-cdk-lib/aws-s3-deployment' ;
51
+
52
+ const modelIntrospectionSchemaKey = 'modelIntrospectionSchema.json' ;
49
53
50
54
/**
51
55
* Singleton factory for AmplifyGraphqlApi constructs that can be used in Amplify project files.
@@ -234,13 +238,14 @@ class DataGenerator implements ConstructContainerEntryGenerator {
234
238
...schemasLambdaFunctions ,
235
239
} ) ;
236
240
let amplifyApi = undefined ;
241
+ let modelIntrospectionSchema : string | undefined = undefined ;
237
242
238
243
const isSandboxDeployment =
239
244
scope . node . tryGetContext ( CDKContextKey . DEPLOYMENT_TYPE ) === 'sandbox' ;
240
245
241
246
try {
242
247
const combinedSchema = combineCDKSchemas ( amplifyGraphqlDefinitions ) ;
243
- const modelIntrospectionSchema = generateModelsSync ( {
248
+ modelIntrospectionSchema = generateModelsSync ( {
244
249
schema : combinedSchema . schema ,
245
250
target : 'introspection' ,
246
251
} ) [ 'model-introspection.json' ] ;
@@ -260,7 +265,6 @@ class DataGenerator implements ConstructContainerEntryGenerator {
260
265
allowDestructiveGraphqlSchemaUpdates : true ,
261
266
_provisionHotswapFriendlyResources : isSandboxDeployment ,
262
267
} ,
263
- modelIntrospectionSchema,
264
268
} ) ;
265
269
} catch ( error ) {
266
270
throw new AmplifyUserError (
@@ -273,6 +277,21 @@ class DataGenerator implements ConstructContainerEntryGenerator {
273
277
) ;
274
278
}
275
279
280
+ // TODO Any risk that this throws?
281
+ const modelIntrospectionSchemaBucket = new Bucket (
282
+ scope ,
283
+ 'modelIntrospectionSchemaBucket' ,
284
+ { enforceSSL : true }
285
+ ) ;
286
+ new BucketDeployment ( scope , 'modelIntrospectionSchemaBucketDeployment' , {
287
+ // See https://github.com/aws-amplify/amplify-category-api/pull/1939
288
+ memoryLimit : 1536 ,
289
+ destinationBucket : modelIntrospectionSchemaBucket ,
290
+ sources : [
291
+ Source . data ( modelIntrospectionSchemaKey , modelIntrospectionSchema ) ,
292
+ ] ,
293
+ } ) ;
294
+
276
295
Tags . of ( amplifyApi ) . add ( TagName . FRIENDLY_NAME , this . name ) ;
277
296
278
297
/**;
@@ -289,10 +308,15 @@ class DataGenerator implements ConstructContainerEntryGenerator {
289
308
ssmEnvironmentEntriesGenerator . generateSsmEnvironmentEntries ( {
290
309
[ `${ this . name } _GRAPHQL_ENDPOINT` ] :
291
310
amplifyApi . resources . cfnResources . cfnGraphqlApi . attrGraphQlUrl ,
311
+ [ `${ this . name } _MODEL_INTROSPECTION_SCHEMA_BUCKET_NAME` ] :
312
+ modelIntrospectionSchemaBucket . bucketName ,
313
+ [ `${ this . name } _MODEL_INTROSPECTION_SCHEMA_KEY` ] :
314
+ modelIntrospectionSchemaKey ,
292
315
} ) ;
293
316
294
317
const policyGenerator = new AppSyncPolicyGenerator (
295
- amplifyApi . resources . graphqlApi
318
+ amplifyApi . resources . graphqlApi ,
319
+ `${ modelIntrospectionSchemaBucket . bucketArn } /${ modelIntrospectionSchemaKey } `
296
320
) ;
297
321
298
322
schemasFunctionSchemaAccess . forEach ( ( accessDefinition ) => {
0 commit comments