Skip to content

Instantly share code, notes, and snippets.

View sdsunjay's full-sized avatar
🏠
Working from home

Sunjay Dhama sdsunjay

🏠
Working from home
View GitHub Profile
@sdsunjay
sdsunjay / pytorch-text-classification-rnn.ipynb
Created April 25, 2024 03:59
pytorch-text-classification-rnn.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sdsunjay
sdsunjay / createWebsiteAndLogBuckets.ts
Last active December 29, 2023 03:40
Within the StaticWebsiteStack class, two S3 buckets are defined: logBucket for storing logs, configured with a lifecycle rule to retain objects for 180 days and siteBucket for hosting the website's content. The siteBucket is configured with SSL enforcement, public access blocking, retention policy, and custom index and error documents. Additiona…
export class StaticWebsiteStack extends Stack {
public readonly siteBucket: s3.Bucket;
public readonly logBucket: s3.Bucket;
public readonly cloudfrontOAI: cloudfront.OriginAccessIdentity;
constructor(parent: Construct, id: string, props: StaticWebsiteStackProps) {
super(parent, id, props);
// Create a new S3 bucket for logs with a lifecycle rule
this.logBucket = new s3.Bucket(this, 'logBucket', {
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { HostedZone } from '../lib/hosted-zone';
/**
* This stack relies on getting the domain name from CDK context.
* Use 'cdk synth -c domain=mystaticsite.com -c subdomain=www'
* Or add the following to cdk.json:
* {
* "context": {
import { aws_route53 as route53 } from 'aws-cdk-lib';
import { CfnOutput, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
export interface HostedZoneProps {
domainName: string;
description: string;
}
export class HostedZone extends Construct {
// CloudFront distribution
const distribution = new Distribution(this, 'SiteDistribution', {
certificate: certificate,
defaultRootObject: "index.html",
domainNames: [siteDomain],
minimumProtocolVersion: SecurityPolicyProtocol.TLS_V1_2_2021,
errorResponses:[
{
httpStatus: 403,
responseHttpStatus: 403,
// inside the StaticWebsite class
// Content bucket
this.siteBucket = new s3.Bucket(this, 'SiteBucket', {
bucketName: props.domainName,
publicReadAccess: false,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
/**
* The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete
interface SlackChannel {
readonly name: string;
readonly id: string;
}
interface SlackBotProps {
readonly workspaceId: string;
readonly channel: SlackChannel;
readonly topics: ReadonlyArray<ITopic>;
}
private generateAnomalyBandVolumeExpression = (metric: Metric) : MathExpression => new MathExpression({
// this expression compares metric value with CloudWatch anomaly detection lower band
usingMetrics: {
["m1"]: metric,
},
expression: `IF(m1 < FIRST(ANOMALY_DETECTION_BAND(m1, 2)), 1, 0)`,
label: `${metric.metricName} Anomaly Detection Volume Below Trend`,
},
);
createAnomalyAlarm(scope: cdk.Construct, jobName: string, pascalName: string, alarmActions: string[]): CfnAlarm {
// The job name is used to match job metrics and alarms
return new CfnAlarm(this, `${jobName}ExecutionTimeAlarm`, {
alarmName: `${jobName}-execution-time`,
comparisonOperator: 'GreaterThanUpperThreshold',
datapointsToAlarm: 1,
evaluationPeriods: 1,
metrics: [
{
id: pascalName,
@sdsunjay
sdsunjay / pytorch-stock-returns.ipynb
Created January 17, 2022 21:06
PyTorch Stock Returns.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.