This file contains 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 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 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 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 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", |
This file contains 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
async function handler(): Promise<{ body: string; statusCode: number }> { | |
console.log("get-stock.handler - started"); | |
return { | |
body: JSON.stringify({ | |
stock: [ | |
{ | |
stockId: 1, | |
description: "hammers", | |
}, |
This file contains 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
// add a security group for the vpc endpoint | |
const sg: ec2.SecurityGroup = new ec2.SecurityGroup(this, "stock-vpc-sg", { | |
vpc, | |
allowAllOutbound: true, | |
securityGroupName: "stock-vpc-sg", | |
}); | |
sg.addIngressRule(ec2.Peer.ipv4(props.cidr), ec2.Port.tcp(443)); | |
// create the vpc endpoint |
This file contains 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 an internal application load balancer | |
this.stockLoadBalancer = new elbv2.ApplicationLoadBalancer( | |
this, | |
"stock-internal-elb", | |
{ | |
vpc, | |
http2Enabled: false, | |
loadBalancerName: "stock-internal-elb", | |
vpcSubnets: vpc.selectSubnets({ | |
subnetType: ec2.SubnetType.PRIVATE_ISOLATED, |
This file contains 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 from "axios"; | |
type Stock = { | |
stockId: number; | |
description: string; | |
}; | |
type StockResponse = { | |
stock: Stock[]; | |
}; |
This file contains 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 from "axios"; | |
async function handler() { | |
const { data } = await axios.get( | |
`https://private-api-id.execute-api.eu-west-1.amazonaws.com/prod/stock`, // 👈 this private call would work | |
{ | |
headers: { | |
"x-api-key": "super-secret-api-key", | |
}, | |
} |