プロジェクト

全般

プロフィール

Temp3

https://zenn.dev/solvio/articles/5675473b392b7f

やさしいMCP入門
Model Context Protocol(MCP)とは?生成 AI の可能性を広げる新しい標準
orcによる入力補助
Kendra GenAI edition + becrock knowledebase化による精度向上活動
agent化
MCP(Model Context Protocol)
web スクレイピング
pdfなどs3文書対応
claude3.7
devinとかclineとか

import mysql from 'mysql2/promise';
import {
  SecretsManagerClient,
  GetSecretValueCommand,
} from '@aws-sdk/client-secrets-manager';

interface RefDvEvent {}

interface SearchCondition {
  colName: string;
  colVal: string | number;
}

interface DBSecret {
  host: string;
  username: string;
  password: string;
  dbname: string;
}

const region = 'ap-northeast-1';
const secretName = 'your-secret-name'; // 実際のSecrets Managerの名前に変更してください

export const lambdaHandler = async (event: RefDvEvent): Promise<mysql.QueryResult> => {
  // Secrets Manager Clientを初期化
  const client = new SecretsManagerClient({ region });

  let secretValue: DBSecret;

  try {
    const command = new GetSecretValueCommand({ SecretId: secretName });
    const response = await client.send(command);

    if (!response.SecretString) {
      throw new Error('Secrets Managerからシークレット文字列を取得できませんでした。');
    }

    secretValue = JSON.parse(response.SecretString);
  } catch (error) {
    console.error('Secrets Manager エラー:', error);
    throw error;
  }

  const connection = await mysql.createConnection({
    host: secretValue.host,
    user: secretValue.username,
    password: secretValue.password,
    database: secretValue.dbname,
  });

  try {
    const rows = await findRecords(connection, 'TABLE_A', [
      { colName: 'column_1', colVal: 1 },
      { colName: 'column_2', colVal: 100 },
    ]);

    console.log('row', rows);
    return rows;
  } catch (error) {
    console.error('データベースエラー:', error);
    throw error;
  } finally {
    await connection.end();
  }
};

async function findRecords(
  connection: mysql.Connection,
  tableName: string,
  conditions: SearchCondition[]
): Promise<mysql.QueryResult> {
  const whereClause = conditions.map((c) => `${c.colName} = ?`).join(' AND ');
  const values = conditions.map((c) => c.colVal);
  const query = `SELECT * FROM ${tableName} WHERE ${whereClause}`;
  const [rows] = await connection.query(query, values);
  return rows;
}
import boto3

def lambda_handler(event, context):
    ec2 = boto3.client('ec2')

    # フィルターで対象のインスタンスを取得
    response = ec2.describe_instances(
        Filters=[
            {
                'Name': 'tag:AutoStop',
                'Values': ['true']
            },
            {
                'Name': 'tag:Name',
                'Values': ['xxxx']
            },
            {
                'Name': 'instance-state-name',
                'Values': ['running']
            }
        ]
    )

    instances_to_stop = []

    # 対象インスタンスのIDをリストアップ
    for reservation in response['Reservations']:
        for instance in reservation['Instances']:
            instances_to_stop.append(instance['InstanceId'])

    if instances_to_stop:
        print(f"Stopping instances: {instances_to_stop}")
        ec2.stop_instances(InstanceIds=instances_to_stop)
    else:
        print("No matching running instances found.")
name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - main

jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true
          lfs: false

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18' # or whatever version you need

      - name: Install dependencies
        run: npm ci

      - name: Build with custom mode
        run: npm run build --mode dev

      - name: Deploy to Azure Static Web Apps
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ZEALOUS_WAVE_0CCD83000 }}
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          action: "upload"
          app_location: "/" # App source code path
          output_location: "dist" # Built app content directory
          skip_app_build: true # ⬅️ 自動ビルドを無効化

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ZEALOUS_WAVE_0CCD83000 }}
          action: "close"

const [columns] = await connection.query(
  `SELECT COLUMN_NAME, COLUMN_COMMENT 
   FROM INFORMATION_SCHEMA.COLUMNS 
   WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?`,
  ['your_database', 'users']
);

for (const col of columns as any[]) {
  console.log(`${col.COLUMN_NAME}: ${col.COLUMN_COMMENT}`);
}
class InvalidParameterError extends Error {
  constructor(message: string) {
    super(message);
    this.name = 'InvalidParameterError';
  }
}