I'm using EC2 backed ECS tasks. When I'm trying to access an AWS service I receive an error "Missing Region".
On the Fargate exactly the same docker image works well. I'm using the latest official AWS Rust create which supposed to automatically detect region in normal conditions. I would like to avoid to hardcode specific region.
Here is how my service is created.
makeFleet(): ecs.AsgCapacityProvider {
const ecsInstanceRole = new iam.Role(this, `${this.appPrefix}-ec2-fleet-role`, {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AmazonEC2ContainerServiceforEC2Role'),
],
});
const launchTemplate = new ec2.LaunchTemplate(this, `${this.appPrefix}-LaunchTemplate`, {
launchTemplateName: `${this.appPrefix}-ecs-LaunchTemplate`,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.C7G, ec2.InstanceSize.LARGE),
machineImage: ecs.EcsOptimizedImage.amazonLinux2(
ecs.AmiHardwareType.ARM,
),
userData: ec2.UserData.forLinux(),
role: ecsInstanceRole,
});
const spotFleet = new autoscaling.AutoScalingGroup(this, `${this.appPrefix}-SpotFleet`, {
vpc: this.cluster.vpc,
minCapacity: 1,
vpcSubnets: this.taskSubnets,
maxCapacity: MAX_SCALING_CAPACITY,
// associatePublicIpAddress: false,
launchTemplate,
});
// Add the Auto Scaling group as a Capacity Provider
const capacityProvider = new ecs.AsgCapacityProvider(this, `${this.appPrefix}-EC2-provider`, {
capacityProviderName: `${this.appPrefix}-EC2-provider`,
autoScalingGroup: spotFleet,
});
this.cluster.addAsgCapacityProvider(capacityProvider);
return capacityProvider;
}
makeTransformationService(
capacityProvider: ecs.AsgCapacityProvider,
): ecsPatterns.ApplicationLoadBalancedEc2Service {
const taskImageOptions: ecsPatterns.ApplicationLoadBalancedTaskImageOptions = {
family: `${this.appPrefix}-transform-task-ec2`,
// image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
image: this.rustImageArm,
containerPort: CONTAINER_PORT,
environment: {
},
logDriver: this.logDriver,
command: ['./transform'],
};
const transformService = new ecsPatterns.ApplicationLoadBalancedEc2Service(this, `${this.appPrefix}-ec2-ingest`, {
cluster: this.cluster,
serviceName: `${this.appPrefix}-transform-ec2`,
cpu: 1024 * 2,
memoryLimitMiB: 1024 * 3,
taskImageOptions,
loadBalancerName: `${this.appPrefix}-transform-lb-ec2`,
propagateTags: ecs.PropagatedTagSource.SERVICE,
publicLoadBalancer: false,
minHealthyPercent: 100,
capacityProviderStrategies: [{
capacityProvider: capacityProvider.capacityProviderName,
weight: 1,
}],
});
return transformService;
}
Should I do any additional config on EC2 backed variant to make it work?