Skip to content

Instantly share code, notes, and snippets.

View leegilmorecode's full-sized avatar
:atom:
That Serverless Guy

Lee Gilmore leegilmorecode

:atom:
That Serverless Guy
View GitHub Profile
@leegilmorecode
leegilmorecode / pipeline-stack.ts
Created March 24, 2023 18:09
Example running Cypress in a CDK Pipelines pipeline
...
// add the feature-dev stage with the relevant environment config to the pipeline
// this is the test stage (beta)
const featureDevStage: PipelineStage = new PipelineStage(
this,
'FeatureDev',
{
...environments.featureDev,
}
@leegilmorecode
leegilmorecode / create-order.cy.ts
Created March 24, 2023 18:04
Example Cypress file which loads our webpage and ensures we can interact with it as defined
describe('create-order', () => {
beforeEach(() => {
cy.visit('/');
});
it('should have modal closed on initial page load', () => {
cy.get('[data-test="create-order-modal"]').should('not.exist');
});
it('should open the create order modal', () => {
@leegilmorecode
leegilmorecode / client-stack.ts
Created March 24, 2023 17:41
Runtime configuration created for a ReactJS frontend and hosted in S3
// Setup Bucket Deployment to automatically deploy new assets and invalidate cache
new s3deploy.BucketDeployment(this, 'ClientBucketDeployment', {
sources: [
s3deploy.Source.asset(path.join(__dirname, '../../../../client/build')),
s3deploy.Source.jsonData('config.json', {
stage,
domainName: props.domainName,
subDomain,
api: `https://api-${stage}.${props.domainName}`,
}), // runtime config for client
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";