t_wの輪郭

AWSIaC

CDK

2023/12/3 5:54:00
あれ『t_wの輪郭』をCI/CDでデプロイ可能にするあれ『CDKでスタック間参照してはならない - Uzabase for Engineers』インフラ以外(更新頻度が高いもの)をCDKで管理してはいけない『CodeDeployで更新するECS ServiceをCDK管理して詰んだ話 - Uzabase for Engineers』『Serverless Frameworkの有償化に伴いAWS CDKとAWS SAMへの移行について検討してみた | DevelopersIO』『Export Amplify project to CDK - JavaScript - AWS Amplify Gen 1 Documentation』『【前編】Amazon CodeCatalyst と AWS CDK で始める CICD パイプライン - サーバーワークスエンジニアブログ』あれCDKでDockerfileをLambdaにデプロイあれあれ『AWS CDK で Lambda 関数の再起ループ保護が設定可能になっていました | DevelopersIO』cdkあれ『Configure security credentials for the AWS CDK CLI - AWS Cloud Development Kit (AWS CDK) v2』Projenあれあれ

あれ

2025/2/1 13:29:00
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as ecs from "aws-cdk-lib/aws-ecs";
import * as ecs_patterns from "aws-cdk-lib/aws-ecs-patterns";

export class CdkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = ec2.Vpc.fromLookup(this, "vpc", {
      vpcId: "vpc-#############"
    })

    const cluster = ecs.Cluster.fromClusterAttributes(this, "ecs-cluster", {
      "clusterName": "hoge-cluster",
      "vpc": vpc,
    });

    // Create a load-balanced Fargate service and make it public
    new ecs_patterns.ApplicationLoadBalancedFargateService(this, "fargate-service", {
      cluster: cluster, // Required
      cpu: 256, // Default is 256
      memoryLimitMiB: 512, // Default is 512
      desiredCount: 1, // Default is 1
      taskImageOptions: { image: ecs.ContainerImage.fromAsset("####") },
      publicLoadBalancer: true, // Default is true
      assignPublicIp: true,
    });
  }
}

手順

  • CDK用のディレクトリと、Next.js用のディレクトリを分ける
  • Fargateを試してみる
  • CDKのスクリプトを書く
  • ローカルからCDKでデプロイする
  • EFSにduckdbファイルを保存する
  • Github ActionsにCDKデプロイする権限をつける
  • Github Actionsのスクリプトを書く
  • 味わう
  • 完成!

あれ

2025/1/10 9:20:00

VPC LambdaのENIがCDKでデプロイした時に変わるうううう
EIPがハゲるううううう

NAT Gateway使うしかないんか……。