With ECS tasks I ran into an issue where ECS is unable to pull images from ECR even though the task is set to run in a PUBLIC subnet. In the console it appears that it is possible to set the Auto-assign public IP for an Event target.
Use Case
I have a cloudwatch event that is set to run every week that fires an ECS task. The ECS task needs to be able to pull the ECR image and communicate with external resources and therefore needs a public IP address.
My current event and target:
const encryptionEventRule = new Rule(this, `${this.projectTag}-encryption-event-rule`, {
schedule: Schedule.expression("rate(7 days)"),
});
encryptionEventRule.addTarget(
new EcsTask({
cluster,
taskDefinition: encryptionTaskDefinition,
taskCount: 1,
subnetSelection: VPC.selectSubnets({
subnetType: SubnetType.PUBLIC,
}),
})
);
Proposed Solution
Just like ECS services I believe a flag for the Auto-assign public IP can be added
In an ECS Service
const service = new FargateService(this, SERVICE_NAME, {
serviceName: SERVICE_NAME,
taskDefinition: taskDefinition,
cluster: cluster,
desiredCount: SERVICE_DESIRED_CONTAINER_COUNT,
assignPublicIp: SERVICE_ASSIGN_PUBLIC_IP,
securityGroup: serviceSecurityGroup,
vpcSubnets: VPC.selectSubnets({
subnetType: SubnetType.PUBLIC,
}),
});
My proposal for an ECS Task event target:
encryptionEventRule.addTarget(
new EcsTask({
cluster,
taskDefinition: encryptionTaskDefinition,
taskCount: 1,
assignPublicIp: SERVICE_ASSIGN_PUBLIC_IP,
subnetSelection: VPC.selectSubnets({
subnetType: SubnetType.PUBLIC,
}),
})
);
Other
The CloudWatch console allows for setting the Auto-assign public IP value when creating an Event Rule that triggers ECS tasks as described here.
This is a 🚀 Feature Request
With ECS tasks I ran into an issue where ECS is unable to pull images from ECR even though the task is set to run in a PUBLIC subnet. In the console it appears that it is possible to set the Auto-assign public IP for an Event target.
Use Case
I have a cloudwatch event that is set to run every week that fires an ECS task. The ECS task needs to be able to pull the ECR image and communicate with external resources and therefore needs a public IP address.
My current event and target:
Proposed Solution
Just like ECS services I believe a flag for the Auto-assign public IP can be added
In an ECS Service
My proposal for an ECS Task event target:
Other
The CloudWatch console allows for setting the Auto-assign public IP value when creating an Event Rule that triggers ECS tasks as described here.
This is a 🚀 Feature Request