AWS CDK CodeStar (Alpha)

2.250.0a0 · active · verified Thu Apr 16

The `aws-cdk-aws-codestar-alpha` library provides AWS Cloud Development Kit (CDK) constructs for interacting with AWS CodeStar. As an 'alpha' module, its APIs are subject to breaking changes and are not recommended for production use. It is currently at version `2.250.0a0` and follows the rapid release cadence of the AWS CDK v2.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart defines a basic CDK stack that includes a `CfnGitHubRepository` from the `aws-cdk-aws-codestar-alpha` module. Note that `CfnGitHubRepository` is an L1 (CloudFormation-level) construct and requires actual GitHub credentials (Personal Access Token) and repository details (owner, name) to be configured, typically via environment variables, for successful deployment. Remember to set `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION`.

import os
from aws_cdk import (
    App, Stack, Environment
)
import aws_cdk.aws_codestar_alpha as codestar_alpha

class MyCodeStarStack(Stack):
    def __init__(self, scope: App, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # IMPORTANT: This is an L1 CloudFormation construct. It requires
        # actual GitHub credentials and repository details for successful deployment.
        # Store sensitive data in environment variables or AWS Secrets Manager.
        github_access_token = os.environ.get("GITHUB_ACCESS_TOKEN", "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN")
        github_owner = os.environ.get("GITHUB_OWNER", "your-github-username")
        repository_name = os.environ.get("GITHUB_REPO_NAME", "my-codestar-repo")

        if github_access_token == "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN":
            print("WARNING: GITHUB_ACCESS_TOKEN not set. This construct will likely fail deployment.")

        # Define a GitHub repository resource for CodeStar
        # This resource integrates an existing GitHub repo with AWS CodeStar.
        codestar_alpha.CfnGitHubRepository(self, "MyGitHubRepo",
            repository_name=repository_name,
            owner=github_owner,
            repository_access_token=github_access_token,
            # is_private=True, # Optional
            # repository_description="My CodeStar managed GitHub repository" # Optional
        )

app = App()
MyCodeStarStack(app, "MyCodeStarStack",
    env=Environment(account=os.environ.get("CDK_DEFAULT_ACCOUNT"), region=os.environ.get("CDK_DEFAULT_REGION"))
)
app.synth()

view raw JSON →