Skip to content

Instantly share code, notes, and snippets.

View allanchua101's full-sized avatar
👹
Coding and grinding

Allan Chua allanchua101

👹
Coding and grinding
View GitHub Profile
@allanchua101
allanchua101 / appconfig-freeform-demo.cfn.yaml
Created April 16, 2022 08:54
Sample CloudFormation template for freeform configuration using AWS AppConfig
AWSTemplateFormatVersion: "2010-09-09"
Description: CloudFormation template used for showcasing AWS AppConfig feature flags
Parameters:
AppName:
Type: String
Description: "Name of application associated with AppConfig instance."
AllowedPattern: ".+"
CostCenter:
const { buildResponse } = require("./helpers/response-builders");
const { loadFrozenModel } = require("./helpers/model-loader");
const MODEL_PATH = "./weights/hate-speech-classifier.json";
let model = null;
module.exports = {
async execute(event, context) {
try {
// if request is CORS-related, quickly respond
if (event.httpMethod.toLowerCase() === "options") {
(async () => {
try {
let [classifier, data] = await Promise.all([loadFrozenModel(), loadData()]);
let results = data.map((i, idx) => {
let actual = getLabel(i.class_id);
let predicted = classifier.classify(i.tweet);
console.clear();
console.log(`Inferring Item ${idx + 1} out of ${data.length}`);
LifecycleConfiguration:
Rules:
- Id: SetToStandardIAAfterAYear
Status: Enabled
Transitions:
- TransitionInDays: "365"
StorageClass: STANDARD_IA
- Id: SetToGlacierAfterThreeYears
Status: Enabled
Transitions:
# Bad Debts in Singapore
# IRAS keeps record of bad debts for a span of years for investigation purposes
# Source: https://www.companyregistrationinsingapore.com.sg/long-keep-business-records/
# 2555 Days = 7 Years
LifecycleConfiguration:
Rules:
- Id: DeleteArtifactAfterConstraintDays
Status: "Enabled"
ExpirationInDays: 2555
#!/bin/bash
# Provide your variable values here
AWS_CF_STACK_NAME="testing-ninja-buckets-a";
ENVIRONMENT_NAME="dev";
AWS_CLI_PROFILE="ninja-boy";
aws cloudformation create-stack \
--stack-name "${AWS_CF_STACK_NAME}" \
--template-body file://tables.cfn.yaml \
--profile "${AWS_CLI_PROFILE}" \
AWSTemplateFormatVersion: "2010-09-09"
Description: >
CloudFormation template used for provisioning SAM artifact storage for environments
that require rapid expiration of build artifacts.
Parameters:
AppName:
Type: String
Description: "Name of application."
AllowedPattern: ".+"
Default: "ninja-buckets"
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >-
SAM template for provisioning the following resources:
- Lambda APIs
- Lambda Layer
- API Gateway
# ___ _
# / _ \__ _ _ __ __ _ _ __ ___ ___| |_ ___ _ __ ___
const { getWeapons } = require("./modules/weapons-query");
const { buildResponse } = require(process.env.AWS
? "/opt/nodejs/response-builder"
: "../base-layer/nodejs/response-builder");
const { sendAlert } = require(process.env.AWS
? "/opt/nodejs/slack-alarm"
: "../base-layer/nodejs/slack-alarm");
module.exports = {
async execute(event, context) {
@allanchua101
allanchua101 / Slack Alarm.js
Last active August 22, 2020 13:58
Sample module used for raising Slack Alarms
const axios = require("axios");
const moment = require("moment");
const slackConfig = require("./slack.config.json");
let buildMarkdown = (err) => {
let output = "";
output += `Something went wrong on our application! :boom:\n`;
output += `*Lambda Function Name:* ${process.env.AWS_LAMBDA_FUNCTION_NAME}\n`;