Skip to content

Instantly share code, notes, and snippets.

View leegilmorecode's full-sized avatar
:atom:
Serverless Hero

Lee Gilmore leegilmorecode

:atom:
Serverless Hero
View GitHub Profile
import * as cdk from 'aws-cdk-lib';
import * as pipelines from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
import { PipelineStage } from '../pipeline-stage/pipeline-stage';
import { environments } from '../pipeline-config/pipeline-config';
export class PipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
export interface EnvironmentConfig {
env: {
account: string;
region: string;
};
stageName: string;
stateful: {
bucketName: string;
};
stateless: {
import * as dotenv from 'dotenv';
import {
Account,
EnvironmentConfig,
Region,
Stage,
} from '../pipeline-types/pipeline-types';
dotenv.config();
import * as apigw from 'aws-cdk-lib/aws-apigateway';
import * as cdk from 'aws-cdk-lib';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as nodeLambda from 'aws-cdk-lib/aws-lambda-nodejs';
import * as path from 'path';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import * as cdk from 'aws-cdk-lib';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import { RemovalPolicy } from 'aws-cdk-lib';
export interface StatefulStackProps extends cdk.StackProps {
bucketName: string;
}
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { EnvironmentConfig } from '../pipeline-types/pipeline-types';
import { StatefulStack } from '../../app/stateful/stateful-stack';
import { StatelessStack } from '../../app/stateless/stateless-stack';
// this is our stage made up of multiple stacks which will be deployed to various environments
// based on config i.e. feature-dev, staging, prod, which also includes our application config
export class PipelineStage extends cdk.Stage {
@leegilmorecode
leegilmorecode / create-customer.ts
Created January 29, 2023 15:49
Example of a AppSync Lambda function resolver using IAM and SigV4 to communicate with private API Gateways
import { AppSyncResolverEvent, AppSyncResolverHandler } from "aws-lambda";
import { Customer } from "../../types";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { URL } from "url";
import fetch from "node-fetch";
import { signRequest } from "../../helpers/request-signer";
import { config } from "../../config";
import { v4 as uuid } from "uuid";
@leegilmorecode
leegilmorecode / internal-system-stack.ts
Created December 14, 2022 18:33
Example of using Amazon EventBridge API Destinations to integrate with an external REST API
// create the orders connection for the api destination
const externalOrdersConnection: events.Connection = new events.Connection(
this,
'ExternalOrdersApiDestinationsConnection',
{
authorization: events.Authorization.apiKey(
'x-api-key',
SecretValue.unsafePlainText('SuperSecretKey!12345') // this is for the demo only
),
description: 'External Orders API Destination Connection',
@leegilmorecode
leegilmorecode / delete-order.ts
Created December 14, 2022 18:25
Example of calling an Amazon Gateway REST API as a proxy to Amazon EventBridge as a direct integration
import * as AWS from 'aws-sdk';
import { APIGatewayProxyHandler, APIGatewayProxyResult } from 'aws-lambda';
import axios from 'axios';
import { v4 as uuid } from 'uuid';
const dynamoDb = new AWS.DynamoDB.DocumentClient();
export const handler: APIGatewayProxyHandler = async ({
@leegilmorecode
leegilmorecode / shared-resources-stack.ts
Created December 14, 2022 18:21
Direct integration between Amazon API Gateway and Amazon EventBridge
// .. creation of the eventbus above
const sharedEdaApi: apigw.RestApi = new apigw.RestApi(
this,
'SharedEdaApi',
{
description: 'shared eda api',
restApiName: 'shared-eda-api',
deploy: true,
deployOptions: {