Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ internal class Configuration
public string GitHubOwner { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_OWNER");
public string GitHubRepository { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_NAME");
public string GitHubBranch { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_BRANCH");

public string GitHubOwnerStaging { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didnt bother to move all of these to a json file yet because we would still need to send in the token key as env variables anyway. i may come back to this in the future

public string GitHubRepositoryStaging { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_NAME_STAGING");
public string GitHubBranchStaging { get; } = Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING");

public Ecrs Ecrs { get; } = new Ecrs();
public const string ProjectRoot = "LambdaRuntimeDockerfiles/Infrastructure/src/Infrastructure";
public static readonly string ProjectName = "aws-lambda-container-images";
public string ProjectName { get; } = "aws-lambda-container-images";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made non static to be consistent


public readonly FrameworkConfiguration[] Frameworks = new[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ internal PipelineStack(
string id,
Configuration configuration,
FrameworkConfiguration frameworkConfiguration,
string gitHubOwner,
string gitHubRepository,
string gitHubBranch,
string pipelineName,
IStackProps props = null) : base(scope, id, props)
{
var sourceArtifact = new Artifact_();
Expand All @@ -47,11 +51,11 @@ internal PipelineStack(

var sourceAction = new GitHubSourceAction(new GitHubSourceActionProps
{
ActionName = configuration.GitHubRepository,
ActionName = gitHubRepository,
Output = sourceArtifact,
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
Branch = configuration.GitHubBranch,
Owner = gitHubOwner,
Repo = gitHubRepository,
Branch = gitHubBranch,
Trigger = GitHubTrigger.WEBHOOK,
OauthToken = SecretValue.SecretsManager(configuration.GitHubTokenSecretName, new SecretsManagerSecretOptions
{
Expand All @@ -62,7 +66,7 @@ internal PipelineStack(
var pipeline = new Pipeline(this, "CodePipeline", new PipelineProps
{
PipelineType = PipelineType.V2,
PipelineName = $"{Configuration.ProjectName}-{frameworkConfiguration.Framework}",
PipelineName = pipelineName,
RestartExecutionOnUpdate = true,
Stages =
[
Expand Down Expand Up @@ -91,9 +95,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down Expand Up @@ -130,9 +134,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down Expand Up @@ -174,9 +178,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down Expand Up @@ -224,9 +228,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down Expand Up @@ -338,9 +342,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down Expand Up @@ -387,9 +391,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down Expand Up @@ -447,9 +451,9 @@ internal PipelineStack(
},
Source = Source.GitHub(new GitHubSourceProps
{
Owner = configuration.GitHubOwner,
Repo = configuration.GitHubRepository,
BranchOrRef = configuration.GitHubBranch
Owner = gitHubOwner,
Repo = gitHubRepository,
BranchOrRef = gitHubBranch
}),
EnvironmentVariables = new Dictionary<string, IBuildEnvironmentVariable>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,42 @@ public PipelinesStage(
string id,
Configuration configuration,
IStageProps props = null) : base(scope, id, props)
{
// Create pipelines for main repository
CreatePipelinesForRepository(configuration,
configuration.ProjectName,
configuration.GitHubOwner,
configuration.GitHubRepository,
configuration.GitHubBranch);

// Create pipelines for staging repository
CreatePipelinesForRepository(configuration,
$"{configuration.ProjectName}-staging",
configuration.GitHubOwnerStaging,
configuration.GitHubRepositoryStaging,
configuration.GitHubBranchStaging);
}

private void CreatePipelinesForRepository(
Configuration configuration,
string pipelinePrefix,
string gitHubOwner,
string gitHubRepository,
string gitHubBranch)
{
for (var i = 0; i < configuration.Frameworks.Length; i++)
{

var pipelineName = $"{pipelinePrefix}-{configuration.Frameworks[i].Framework}";

new PipelineStack(this,
configuration.Frameworks[i].Framework,
$"{pipelinePrefix}-{configuration.Frameworks[i].Framework}",
Copy link
Contributor Author

@GarrettBeatty GarrettBeatty Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cloudformation seems to automatically uses the parent pipeline name+ this for the name of the stack and we get something like

aws-lambda-container-images-aws-lambda-container-images-staging-net9

but i dont really care about the stack name too much to be honest. This was the only way i found to make the pipeline name + what appears in the ui for the pipeline in the main pipeline look correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not a fan of this, but not a big deal

configuration,
configuration.Frameworks[i],
gitHubOwner,
gitHubRepository,
gitHubBranch,
pipelineName,
new StackProps
{
TerminationProtection = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void Main(string[] args)

new SelfMutatingPipelineStack(
app,
Configuration.ProjectName,
configuration.ProjectName,
configuration,
new StackProps
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,19 @@ internal SelfMutatingPipelineStack(
{ "AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL",
new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value =
System.Environment.GetEnvironmentVariable("AWS_LAMBDA_DOTNET_FRAMEWORK_CHANNEL") ?? string.Empty } },
{ "AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING",
new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value =
System.Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING") ?? string.Empty } },
{ "AWS_LAMBDA_GITHUB_REPO_NAME_STAGING",
new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value =
System.Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_NAME_STAGING") ?? string.Empty } },
{ "AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING",
new BuildEnvironmentVariable { Type = BuildEnvironmentVariableType.PLAINTEXT, Value =
System.Environment.GetEnvironmentVariable("AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING") ?? string.Empty } },
};

// Self mutation

Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove this empty line as it adds unnecessary whitespace without improving readability.

Suggested change

Copilot uses AI. Check for mistakes.

var pipeline = new CodePipeline(this, "SelfMutatingPipeline", new CodePipelineProps
{
PipelineName = id,
Expand Down Expand Up @@ -114,6 +124,6 @@ internal SelfMutatingPipelineStack(
});

// Add a stage in the pipeline to deploy the Lambda container pipelines
pipeline.AddStage(new PipelinesStage(this, Configuration.ProjectName, configuration));
pipeline.AddStage(new PipelinesStage(this, configuration.ProjectName, configuration));
}
}
15 changes: 14 additions & 1 deletion bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ param (
[Parameter(Mandatory = $true, HelpMessage = "GitHub repository branch name.")]
[string] $GitHubRepoBranch,

[Parameter(Mandatory = $true, HelpMessage = "GitHub staging repository owner name.")]
[string] $GitHubRepoOwnerStaging,

[Parameter(Mandatory = $true, HelpMessage = "GitHub staging repository name.")]
[string] $GitHubRepoNameStaging,

[Parameter(Mandatory = $true, HelpMessage = "GitHub staging repository branch name.")]
[string] $GitHubRepoBranchStaging,

[Parameter(Mandatory = $false, HelpMessage = "ECR URI to store Stage images.")]
[string] $StageEcr,

Expand All @@ -44,9 +53,13 @@ $env:AWS_LAMBDA_GITHUB_REPO_OWNER = $GitHubRepoOwner
$env:AWS_LAMBDA_GITHUB_REPO_NAME = $GitHubRepoName
$env:AWS_LAMBDA_GITHUB_REPO_BRANCH = $GitHubRepoBranch

$env:AWS_LAMBDA_GITHUB_REPO_OWNER_STAGING = $GitHubRepoOwnerStaging
$env:AWS_LAMBDA_GITHUB_REPO_NAME_STAGING = $GitHubRepoNameStaging
$env:AWS_LAMBDA_GITHUB_REPO_BRANCH_STAGING = $GitHubRepoBranchStaging

$env:AWS_LAMBDA_STAGE_ECR = $StageEcr
$env:AWS_LAMBDA_BETA_ECRS = $BetaEcrs
$env:AWS_LAMBDA_PROD_ECRS = $ProdEcrs

npx cdk bootstrap --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess aws://$PipelineAccountId/$Region
npx cdk deploy --require-approval never --all
npx cdk deploy --require-approval never --all