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
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 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
// 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 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 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 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 from "axios"; | |
type Stock = { | |
stockId: number; | |
description: string; | |
}; | |
type StockResponse = { | |
stock: Stock[]; | |
}; |
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 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", | |
}, | |
} |
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
EventRule: | |
Type: AWS::Events::Rule | |
Properties: | |
Description: 'PayslipUploadedEventRule' | |
EventBusName: 'HREventBus' | |
EventPattern: | |
account: | |
- !Sub '${AWS::AccountId}' | |
source: | |
- 'payslip.uploaded' |
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 { SNSEvent, EventBridgeEvent, Handler } from 'aws-lambda'; | |
export const handler: Handler<SNSEvent | EventBridgeEvent<any, any>> = (event) => { | |
console.log('Fulfilment handler'); | |
console.log('event = ' + JSON.stringify(event)); | |
}; |
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, APIGatewayEvent } from 'aws-lambda'; | |
import * as AWS from 'aws-sdk'; | |
import { validate } from '../shared/validator'; | |
import { OrderCreated } from '../../schema/order_create/ordercreated/OrderCreated'; | |
import { OrderCreatedItem } from '../../schema/order_create/ordercreated/OrderCreatedItem'; | |
import * as schema from '../../schema/order_create/ordercreated/[email protected]'; | |
const eventBridge = new AWS.EventBridge({ region: 'eu-west-1' }); | |
export const handler: APIGatewayProxyHandler = async ({ body }: APIGatewayEvent): Promise<APIGatewayProxyResult> => { |
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
service: serverless-event-bridge | |
variablesResolutionMode: 20210326 | |
provider: | |
name: aws | |
runtime: nodejs14.x | |
lambdaHashingVersion: 20201221 | |
memorySize: 128 | |
stage: ${opt:stage, 'dev'} | |
region: ${opt:region, 'eu-west-1'} | |
eventBridge: |
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
export const randomErrors = (): void | Error => { | |
if (Math.random() > 0.9) { | |
throw new Error('spurious error'); | |
} | |
}; |