Surf Turf
12/16/2021, 6:10 PMSurf Turf
12/16/2021, 7:05 PMimport * as sst from '@serverless-stack/resources'
import * as appsync from '@aws-cdk/aws-appsync'
export default class AppsyncCacheExampleStack extends sst.Stack {
constructor(scope: <http://sst.App|sst.App>, id: string, props?: sst.StackProps) {
super(scope, id, props)
const appSyncApi = new sst.AppSyncApi(this, 'AppSyncApi', {
graphqlApi: {
xrayEnabled: true,
schema: ['graphql/cache-example.graphql'],
},
dataSources: {
fooDS: 'src/cache-example/foo.handler',
},
})
const apiId = appSyncApi.graphqlApi.apiId
const ttl = 30
new appsync.CfnApiCache(this, 'ApiCache', {
apiCachingBehavior: 'PER_RESOLVER_CACHING',
apiId,
ttl,
type: 'SMALL',
// the properties below are optional
atRestEncryptionEnabled: false,
transitEncryptionEnabled: false,
})
new appsync.CfnResolver(this, 'MyCfnResolver', {
apiId,
fieldName: 'getFooById',
typeName: 'Query',
cachingConfig: {
cachingKeys: ['$context.args.id'],
ttl,
},
dataSourceName: appSyncApi.getDataSource('fooDS')?.name,
kind: 'UNIT',
})
// Show the endpoint in the output
this.addOutputs({
AppsyncEndpoint: appSyncApi.url,
apiId,
})
}
}