Skip to content

Instantly share code, notes, and snippets.

View tmokmss's full-sized avatar

Masashi Tomooka tmokmss

View GitHub Profile
@tmokmss
tmokmss / handler.ts
Created April 22, 2024 05:01
Cross region AWS API proxy for Step Functions
import { Handler } from 'aws-lambda';
type Input = {
/**
* AWS Region name to call the service
*/
targetRegion: string;
/**
* AWS service name (must be in AWS SDK for JS v3 style)
@tmokmss
tmokmss / main.rs
Created January 1, 2024 14:07
Aurora Data API Proxy with pgwire
use std::fmt::Debug;
use std::sync::Arc;
use async_trait::async_trait;
use aws_sdk_rdsdata::error::ProvideErrorMetadata;
use futures::{stream, Sink, SinkExt, StreamExt};
use tokio::net::TcpListener;
use pgwire::api::auth::noop::NoopStartupHandler;
use pgwire::api::portal::Portal;
@tmokmss
tmokmss / index.mjs
Last active April 18, 2024 02:44
Claudeに{を食わせる
import { BedrockRuntimeClient, InvokeModelCommand } from '@aws-sdk/client-bedrock-runtime';
const client = new BedrockRuntimeClient({ region: 'us-east-1' });
const sendPrompt = async (prompt) => {
const command = new InvokeModelCommand({
modelId: 'anthropic.claude-instant-v1',
body: JSON.stringify({
prompt,
temperature: 0.6,
@tmokmss
tmokmss / typescript.json
Last active December 11, 2022 03:57
VSCode snippet for AWS CDK
{
"CDK Construct": {
"prefix": "cdk-constructv2",
"body": [
"import { Construct } from 'constructs';",
"",
"export interface ${1:ConstructName}Props {",
"",
"}",
"",
@tmokmss
tmokmss / ISUCON_SOLO.md
Last active September 4, 2023 01:03
ソロISUCON 道標

準備

  • リポジトリの作成 (app, infra)
  • リポジトリをローカルに pull
  • AWSアカウントにログイン
  • ターミナルのウィンドウ配置

ソロISUCON 道標

具体的なコマンドはこちらに: https://github.com/tmokmss/isucon12q-infra

  1. 環境のセットアップ
@tmokmss
tmokmss / index.js
Last active May 12, 2022 00:42
Survey form powered by Lambda function URL
const https = require('https')
exports.handler = async (event) => {
console.log(event)
const req = event.requestContext.http;
const sourceIp = req.sourceIp;
// can perform IP address restriction here
// e.g. if (sourceIp != "11.4.51.4") throw new Error()
@tmokmss
tmokmss / job.ts
Created March 30, 2022 14:18
A standalone construct for DataBrew Job
import { Construct } from 'constructs';
import { aws_databrew as databrew } from 'aws-cdk-lib';
import { IBucket } from 'aws-cdk-lib/aws-s3';
import { IRole } from 'aws-cdk-lib/aws-iam';
export interface JobProps {
readonly name: string;
readonly inputBucket: IBucket;
readonly inputKey: string;
readonly outputBucket: IBucket;
@tmokmss
tmokmss / init_workspace.sh
Created March 2, 2022 05:20
Create AWS resources for Terraform S3 backend
#!/bin/bash
# A shell script to create AWS resources for Terraform S3 backend
STACK_NAME=TerraformStateStack-6nc8asv # add random suffix to prevent from colliding with any existing stacks
TEMPLATE_PATH="$(dirname "$0")/workspace_cfn.yaml"
aws cloudformation deploy --stack-name $STACK_NAME --template-file $TEMPLATE_PATH --no-cli-pager
aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs" --no-cli-pager
@tmokmss
tmokmss / main.tf
Created July 21, 2021 09:07
Terraform that enables AWS Config
resource "aws_s3_bucket" "aws_config_bucket" {
bucket_prefix = "aws-config-"
server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
}
@tmokmss
tmokmss / fargate-stack.ts
Created January 20, 2021 01:39
Fargate with ECS CDK Definition
import * as cdk from '@aws-cdk/core';
import * as ecs from '@aws-cdk/aws-ecs';
import * as efs from '@aws-cdk/aws-efs';
import * as ec2 from '@aws-cdk/aws-ec2';
export class FargateStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'vpc');