CDK version: 1.83.0 (build 827c5f4)
Install Python 3 and AWS CLI. Install the AWS CLI because it's needed (but not necessarily) to switch the AWS account that runs the CDK using the profile. After installation, set the required profile.
brew install python3 awscli
aws configure --profile Profile name
brew install aws-cdk
Execute the command on a blank directory.
cdk init sample-app --language python
setup
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
TODO
from aws_cdk import (
aws_iam as iam,
aws_ecr as ecr,
core
)
class RepositoryStack(core.Stack):
def __init__(self, scope: core.Construct, construct_id: str, stage: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
#Create repository in ECR and set life cycle and permissions (dev account only)
if stage == 'dev':
lifecycle_rules = [
ecr.LifecycleRule(
description='Delete old images',
max_image_count=5,
rule_priority=1,
tag_status=ecr.TagStatus.UNTAGGED
)
]
repository = ecr.Repository(
self,
'EcrRepository',
lifecycle_rules=lifecycle_rules,
repository_name='seriwb/nanika'
)
repository.grant_pull(iam.AccountPrincipal('staging account'))
repository.grant_pull(iam.AccountPrincipal('production account'))
TBD --Creating an EC2 instance - AMI - IAM --Existing VPC --Existing subnet --Security group --Target group --Tag
Recommended Posts