This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| APIGatewayEvent, | |
| APIGatewayProxyHandler, | |
| APIGatewayProxyResult, | |
| } from "aws-lambda"; | |
| import { Collection, Db, InsertOneResult, MongoClient } from "mongodb"; | |
| import { buildMongoClient, connectToDatabase } from "../../../common"; | |
| import { config } from "../../../config"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import axios, { AxiosResponse } from "axios"; | |
| export const findOne = async ( | |
| serviceLayerUrl: string, | |
| collectionName: string, | |
| id: string | number | |
| ) => { | |
| const { data }: { data: Order } = await axios.post( | |
| `http://${serviceLayerUrl}/findOne`, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // updateBlog mutation with cache invalidation | |
| blogTableDataSource.createResolver({ | |
| typeName: "Mutation", | |
| fieldName: "updateBlog", | |
| // this is an example of a vtl template generated with the helper methods | |
| requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem( | |
| appsync.PrimaryKey.partition("id").is("input.id"), | |
| appsync.Values.projecting("input") | |
| ), | |
| // this is an example of an inline vtl response template (you can also pull in from a file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #set($cachingKeys = {}) | |
| $util.qr($cachingKeys.put("context.arguments.id", $context.arguments.id)) | |
| $extensions.evictFromApiCache("Query", "getBlogNoDax", $cachingKeys) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // appsync lambda data source | |
| const blogNoDaxDataSource: appsync.LambdaDataSource = | |
| new appsync.LambdaDataSource(this, "GetBlogNoDaxLambdaDataSource", { | |
| api, | |
| lambdaFunction: getBlogNoDaxHandler, | |
| description: "Get Blog (no dax) Lambda Data Source", | |
| name: "GetBlogNoDaxLambdaDataSource", | |
| }); | |
| // appsync resolver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as AWS from "aws-sdk"; | |
| import { APIGatewayProxyHandler, APIGatewayProxyResult } from "aws-lambda"; | |
| import { v4 as uuid } from "uuid"; | |
| const fs = require("fs").promises; | |
| const s3 = new AWS.S3(); | |
| // a function to write the files to tmp on the lambda |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { APIGatewayProxyHandler, APIGatewayProxyResult } from "aws-lambda"; | |
| import { v4 as uuid } from "uuid"; | |
| const data = require("data-api-client")({ | |
| secretArn: process.env.SECRET_ARN as string, | |
| resourceArn: process.env.CLUSTER_ARN as string, | |
| database: process.env.DB, | |
| continueAfterTimeout: true, | |
| includeResultMetadata: false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as AWS from "aws-sdk"; | |
| import { AppSyncResolverEvent, AppSyncResolverHandler } from "aws-lambda"; | |
| import { Blog, QueryIdArgs } from "../../types"; | |
| import { v4 as uuid } from "uuid"; | |
| const AmazonDaxClient = require("amazon-dax-client"); | |
| const dax = new AmazonDaxClient({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // integrate the lambda to the method - GET /blogs | |
| blogs.addMethod( | |
| "GET", | |
| new apigw.LambdaIntegration(listBlogsHandler, { | |
| proxy: true, | |
| allowTestInvoke: true, | |
| }) | |
| ); | |
| // integrate the lambda to the method - GET /blog/{id} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // create the rest API for accessing our lambdas | |
| const api: apigw.RestApi = new apigw.RestApi(this, "blogs-api", { | |
| description: "blogs api gateway", | |
| deploy: true, | |
| deployOptions: { | |
| // this enables caching on our api gateway, with a ttl of five minutes (unless overridden per method) | |
| cachingEnabled: true, | |
| cacheClusterEnabled: true, | |
| cacheDataEncrypted: true, | |
| stageName: "prod", |