Skip to content

Instantly share code, notes, and snippets.

View cagingulsen's full-sized avatar
🌩️
Focusing

Kemal Cagin Gulsen cagingulsen

🌩️
Focusing
View GitHub Profile
@cagingulsen
cagingulsen / 0_reuse_code.js
Created December 21, 2016 12:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cagingulsen
cagingulsen / hello.js
Last active January 23, 2022 21:56
Hello World Lambda Function
exports.handler = function(event, context) {
console.log('Hello, Cloudwatch!');
context.succeed('Hello, World!');
};
@cagingulsen
cagingulsen / main.ts
Created January 23, 2022 22:19
AWS CDK App
import { App, Stack, StackProps } from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
export class LambdaStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps = {}) {
super(scope, id, props);
new lambda.Function(this, 'ExampleFunction', {
functionName: 'example-lambda',
const { AwsCdkTypeScriptApp } = require('projen');
const project = new AwsCdkTypeScriptApp({
cdkVersion: '1.95.2',
defaultReleaseBranch: 'main',
name: 'prod-ready-cdk',
// cdkDependencies: undefined, /* Which AWS CDK modules (those that start with "@aws-cdk/") this app uses. */
// deps: [], /* Runtime dependencies of this module. */
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */
// devDeps: [], /* Build dependencies for this module. */
const { awscdk } = require('projen');
const project = new awscdk.AwsCdkTypeScriptApp({
authorAddress: '[email protected]',
authorName: 'Kemal Cagin Gulsen',
cdkVersion: '2.8.0',
defaultReleaseBranch: 'main',
name: 'prod-ready-cdk',
description: 'A CDK project for my blog posts',
repositoryUrl: 'https://github.com/cagingulsen/prod-ready-cdk.git',
keywords: [
import * as cdk from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { LambdaStack } from '../src/main';
test('Lambda created', () => {
const app = new cdk.App();
const stack = new LambdaStack(app, 'LambdaStack');
const template = Template.fromStack(stack);
template.resourceCountIs('AWS::Lambda::Function', 1);
@cagingulsen
cagingulsen / lambda-stack.ts
Last active March 1, 2022 21:16
for Production-Ready CDK - CDK Pipelines
import { Stack, StackProps } from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
// example cdk app stack
export class LambdaStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
@cagingulsen
cagingulsen / cdk-pipeline-stack.ts
Last active March 2, 2022 17:06
for Production-Ready CDK - CDK Pipelines
import { Stack, StackProps, Stage } from 'aws-cdk-lib';
import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines';
import { Construct } from 'constructs';
import { LambdaStack } from './lambda-stack';
// 3a. We define a Lambda Stage that deploys the Lambda Stack.
export class LambdaStage extends Stage {
constructor(scope: Construct, id: string) {
super(scope, id);
new LambdaStack(this, 'LambdaStack');
@cagingulsen
cagingulsen / main.ts
Created March 1, 2022 21:15
for Production-Ready CDK - CDK Pipelines
import { App } from 'aws-cdk-lib';
import { CdkPipelineStack } from './cdk-pipeline-stack';
// for development, use account/region from cdk cli
const devEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
};
const app = new App();
@cagingulsen
cagingulsen / lambda-stack.test.ts
Created March 1, 2022 21:21
for Production-Ready CDK - CDK Pipelines
import * as cdk from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { LambdaStack } from '../src/lambda-stack';
test('Lambda created', () => {
const app = new cdk.App();
const stack = new LambdaStack(app, 'LambdaStack');
const template = Template.fromStack(stack);
template.resourceCountIs('AWS::Lambda::Function', 1);