Class AwsDirectDeployer

java.lang.Object
com.cloudforgeci.api.deploy.aws.AwsDirectDeployer
All Implemented Interfaces:
AutoCloseable

public final class AwsDirectDeployer extends Object implements AutoCloseable
Creates and incrementally updates CloudFormation stacks on AWS via change sets.

Backs CloudForgeDeployment's AWS case: the direct-deploy counterpart to LocalStackDeployer/MiniStackDeployer, without the emulator-specific steps (Cognito/RDS secret reconciliation, ECS restarts after secret sync), which AWS handles through CDK's Secrets Manager integration.

Targets AWS by default, but redirects to a local emulator when Manager itself runs inside one, using the same LOCALSTACK_ENDPOINT/AWS_ENDPOINT_URL detection as LocalStackDeployer.resolveEndpoint(). Without the endpoint override, a Manager instance hosted on LocalStack would call the public CloudFormation endpoint instead of the emulator.

Every stack created or updated is tagged with the cloudforge:managed/ cloudforge:application/cloudforge:runtime convention that ApplicationFargateStack/ApplicationEc2Stack apply via Tags.of(this).add(...). The tags are required by Manager's inventory (StackListingPolicy) and by the aws:RequestTag/aws:ResourceTag conditions in ManagerOperatorIamSupport.deployStatements. Those conditions evaluate the stack-level Tags parameter on the API call, not resource-level tags in the template; this class controls the former.

Test coverage: AwsDirectDeployerTest runs this class against LocalStack via the injectable-client constructor, which exercises every code path except AWS's own network and authentication. The change-set create/execute/wait sequence mirrors LocalStackDeployer's.

  • Field Details

  • Constructor Details

  • Method Details

    • deploy

      public AwsStackDeployResult deploy(String stackName, Path template) throws IOException
      Creates or updates stackName from template via a change set. No-op (returns noOp = true) when the stack already matches the candidate template.
      Throws:
      IOException
    • deploy

      public AwsStackDeployResult deploy(String stackName, Path template, StackProgressListener listener) throws IOException
      Same as deploy(String, Path), additionally reporting each CloudFormation stack event to listener as it happens (may be null to skip live reporting).
      Throws:
      IOException
    • previewChangeSet

      public AwsStackDeployResult previewChangeSet(String stackName, Path template) throws IOException
      Creates a change set for stackName from template and returns its resource-change summary without executing it — the create-time equivalent of cdk deploy --no-execute. The change set is deleted immediately after being described, so nothing in the account outlives this call; unlike the CDK CLI's own --no-execute, there's no changeset left behind to inspect or execute later, since this is a one-shot preview, not a staged deploy. No-op (returns noOp = true) when the stack already matches the candidate template, exactly like deploy(String, Path).
      Throws:
      IOException
    • delete

      public void delete(String stackName) throws IOException
      Throws:
      IOException
    • delete

      public void delete(String stackName, StackProgressListener listener) throws IOException
      Same as delete(String), additionally reporting each CloudFormation stack event to listener as it happens (may be null to skip live reporting).
      Throws:
      IOException
    • stackExists

      public boolean stackExists(String stackName)
    • outputs

      public Map<String,String> outputs(String stackName)
    • verifyDeployment

      public Map<String,String> verifyDeployment(String stackName) throws IOException
      Confirm the stack exists and return its outputs.
      Throws:
      IOException - when the stack is missing or outputs cannot be read
    • resolveCdkBootstrapParameters

      public static String resolveCdkBootstrapParameters(String templateBody) throws IOException
      CDK injects BootstrapVersion as AWS::SSM::Parameter::Value<String>, whose default resolves from /cdk-bootstrap/hnb659fds/version in SSM Parameter Store. That parameter exists in a bootstrapped AWS account but never in a local emulator or an AWS Marketplace buyer's own (never-bootstrapped) account, where CloudFormation rejects the reference ("Parameter BootstrapVersion should either have input value or default value") before creating a single resource. Applies the same rewrite as LocalStackTemplateAdapter.resolveCdkBootstrapParameters, duplicated because cloudforge-api cannot depend on cloudforge-localstack. Called for every deploy target, not just a local emulator's -- a self-contained template must never depend on the deploying account's bootstrap state. Public so CloudForgeSynthesizer #synthesizeForMarketplace can also apply it directly to the template file it writes to disk, not just to the in-memory body this class sends to CloudFormation -- a file meant to be uploaded to AWS Marketplace has no later deploy-time rewrite step to rely on.
      Throws:
      IOException
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable