# Ec2DeployActionProps

Struct · Stable

Construction properties of `Ec2DeployAction`.

Extends: [CommonAwsActionProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.CommonAwsActionProps.html)
Used as props by: [Ec2DeployAction](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.Ec2DeployAction.html)

- Source: [`aws-codepipeline-actions/lib/ec2/deploy-action.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-codepipeline-actions/lib/ec2/deploy-action.ts#L13)
- Type last changed: v2.201.0 · 13 Jun 2025

## Example

TypeScript:

```ts
const sourceOutput = new codepipeline.Artifact();

const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
  pipelineType: codepipeline.PipelineType.V2,
});
const deployAction = new codepipeline_actions.Ec2DeployAction({
  actionName: 'Ec2Deploy',
  input: sourceOutput,
  instanceType: codepipeline_actions.Ec2InstanceType.EC2,
  instanceTagKey: 'Name',
  instanceTagValue: 'MyInstance',
  deploySpecifications: codepipeline_actions.Ec2DeploySpecifications.inline({
    targetDirectory: '/home/ec2-user/deploy',
    preScript: 'scripts/pre-deploy.sh',
    postScript: 'scripts/post-deploy.sh',
  }),
});
const deployStage = pipeline.addStage({
  stageName: 'Deploy',
  actions: [deployAction],
});
```

Python:

```python
source_output = codepipeline.Artifact()

pipeline = codepipeline.Pipeline(self, "MyPipeline",
    pipeline_type=codepipeline.PipelineType.V2
)
deploy_action = codepipeline_actions.Ec2DeployAction(
    action_name="Ec2Deploy",
    input=source_output,
    instance_type=codepipeline_actions.Ec2InstanceType.EC2,
    instance_tag_key="Name",
    instance_tag_value="MyInstance",
    deploy_specifications=codepipeline_actions.Ec2DeploySpecifications.inline(
        target_directory="/home/ec2-user/deploy",
        pre_script="scripts/pre-deploy.sh",
        post_script="scripts/post-deploy.sh"
    )
)
deploy_stage = pipeline.add_stage(
    stage_name="Deploy",
    actions=[deploy_action]
)
```

Java:

```java
Artifact sourceOutput = new Artifact();

Pipeline pipeline = Pipeline.Builder.create(this, "MyPipeline")
        .pipelineType(PipelineType.V2)
        .build();
Ec2DeployAction deployAction = Ec2DeployAction.Builder.create()
        .actionName("Ec2Deploy")
        .input(sourceOutput)
        .instanceType(Ec2InstanceType.EC2)
        .instanceTagKey("Name")
        .instanceTagValue("MyInstance")
        .deploySpecifications(Ec2DeploySpecifications.inline(Ec2DeploySpecificationsInlineProps.builder()
                .targetDirectory("/home/ec2-user/deploy")
                .preScript("scripts/pre-deploy.sh")
                .postScript("scripts/post-deploy.sh")
                .build()))
        .build();
IStage deployStage = pipeline.addStage(StageOptions.builder()
        .stageName("Deploy")
        .actions(List.of(deployAction))
        .build());
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var sourceOutput = new Artifact();

var pipeline = new Pipeline(this, "MyPipeline", new PipelineProps {
    PipelineType = PipelineType.V2
});
var deployAction = new Ec2DeployAction(new Ec2DeployActionProps {
    ActionName = "Ec2Deploy",
    Input = sourceOutput,
    InstanceType = Ec2InstanceType.EC2,
    InstanceTagKey = "Name",
    InstanceTagValue = "MyInstance",
    DeploySpecifications = Ec2DeploySpecifications.Inline(new Ec2DeploySpecificationsInlineProps {
        TargetDirectory = "/home/ec2-user/deploy",
        PreScript = "scripts/pre-deploy.sh",
        PostScript = "scripts/post-deploy.sh"
    })
});
var deployStage = pipeline.AddStage(new StageOptions {
    StageName = "Deploy",
    Actions = new [] { deployAction }
});
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
sourceOutput := codepipeline.NewArtifact()

pipeline := codepipeline.NewPipeline(this, jsii.String("MyPipeline"), &PipelineProps{
	PipelineType: codepipeline.PipelineType_V2,
})
deployAction := codepipeline_actions.NewEc2DeployAction(&Ec2DeployActionProps{
	ActionName: jsii.String("Ec2Deploy"),
	Input: sourceOutput,
	InstanceType: codepipeline_actions.Ec2InstanceType_EC2,
	InstanceTagKey: jsii.String("Name"),
	InstanceTagValue: jsii.String("MyInstance"),
	DeploySpecifications: codepipeline_actions.Ec2DeploySpecifications_Inline(&Ec2DeploySpecificationsInlineProps{
		TargetDirectory: jsii.String("/home/ec2-user/deploy"),
		PreScript: jsii.String("scripts/pre-deploy.sh"),
		PostScript: jsii.String("scripts/post-deploy.sh"),
	}),
})
deployStage := pipeline.AddStage(&StageOptions{
	StageName: jsii.String("Deploy"),
	Actions: []IAction{
		deployAction,
	},
})
```

## Properties

- `actionName`: string (required) — The physical, human-readable name of the Action.

  Note that Action names must be unique within a single Stage.

- `deploySpecifications`: [Ec2DeploySpecifications](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.Ec2DeploySpecifications.html) (required) — The deploy specifications.

- `input`: [Artifact](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.Artifact.html) (required) — The input artifact to deploy to EC2 instances.

- `instanceTagKey`: string (required) — The tag key of the instances that you created in Amazon EC2.

- `instanceTagValue`: string — The tag value of the instances that you created in Amazon EC2.

  **Default:** all instances with `instanceTagKey` will be matched

- `instanceType`: [Ec2InstanceType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.Ec2InstanceType.html) (required) — The type of instances or SSM nodes created in Amazon EC2.

  You must have already created, tagged, and installed the SSM agent on all instances.

- `maxBatch`: [Ec2MaxInstances](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.Ec2MaxInstances.html) — The number or percentage of instances that can deploy in parallel.

  **Default:** No configuration

- `maxError`: [Ec2MaxInstances](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline_actions.Ec2MaxInstances.html) — Stop the task after the task fails on the specified number or percentage of instances.

  **Default:** No configuration

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The Role in which context's this Action will be executing in.

  **Default:** a new Role will be generated

  The Pipeline's Role will assume this Role
  (the required permissions for that will be granted automatically)
  right before executing this Action.
  This Action will be passed into your `IAction.bind`
  method in the `ActionBindOptions.role` property.

- `runOrder`: number = 1 — The runOrder property for this Action.

  RunOrder determines the relative order in which multiple Actions in the same Stage execute.

- `targetGroups`: [ITargetGroup](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.ITargetGroup.html)[] — The list of target groups for deployment. You must have already created the target groups.

  **Default:** No target groups

  Target groups provide a set of instances to process specific requests.
  If the target group is specified, instances will be removed from the target group before deployment and added back to the target group after deployment.

- `variablesNamespace`: string — The name of the namespace to use for variables emitted by this action.

  **Default:** a name will be generated, based on the stage and action names, if any of the action's variables were referenced - otherwise, no namespace will be set
