0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS CDK(Python)用の環境をDockerで構築する

Last updated at Posted at 2024-01-31

DockerFileとdocker-compose.ymlと、appディレクトリ(中身は空でOK)を同階層に配置。

DockerFile

FROM nikolaik/python-nodejs:python3.12-nodejs20-slim

RUN apt update && apt clean

RUN pip3 install awscli --upgrade \
    && pip3 install --upgrade pip \
    && pip3 install aws-cdk-lib \
    && npm install -g aws-cdk
docker-compose.yml
version: '3'

services:
  aws-cdk:
    build: .
    image: aws_cdk_image
    volumes:
      - ./app:/app
    container_name: aws_cdk
    tty: true

コマンド

docker compose up -d
docker exec -it aws_cdk /bin/bash

mkdir -p /app/sample
cd /app/sample

cdk init --language python
cdk ls
cdk synth -o cloudformation --no-version-reporting --path-metadata false
# cdk synth [app_name] -o cloudformation --no-version-reporting --path-metadata false
app.py
#!/usr/bin/env python3
import os

import aws_cdk as cdk
from aws_cdk import (
    DefaultStackSynthesizer
)

from sample.sample_stack import SampleStack

app = cdk.App()
SampleStack(app, "SampleStack", synthesizer=DefaultStackSynthesizer(
        generate_bootstrap_version_rule=False
    )
)

app.synth()
sample/sample_stack.py
from aws_cdk import (
    Stack,
    aws_s3_deployment as s3deploy,
    aws_s3 as s3,
    RemovalPolicy
)
from constructs import Construct

class SampleStack(Stack):

    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        s3bucket = s3.Bucket(
            self,
            "MyS3Bucket",
            bucket_name = "cdk-test-bucket-yyyymmdd",
            versioned=False,
            removal_policy=RemovalPolicy.DESTROY
        )
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?