-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ecs): EC2 metadata access is blocked when using EC2 capacity provider for autoscaling #28437
Changes from 2 commits
df24694
fbd90d7
4d434b5
2c722c3
ca9b9b8
42c815c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1110,6 +1110,67 @@ describe('ec2 task definition', () => { | |
}], | ||
}); | ||
}); | ||
|
||
test('correctly sets env variables when using EC2 capacity provider with AWSVPC mode', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add another test with |
||
// GIVEN AWS-VPC network mode | ||
const stack = new cdk.Stack(); | ||
const taskDefiniton = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef', { | ||
networkMode: ecs.NetworkMode.AWS_VPC, | ||
}); | ||
taskDefiniton.addContainer('some-container', { | ||
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), | ||
memoryLimitMiB: 512, | ||
environment: { | ||
SOME_VARIABLE: 'some-value', | ||
}, | ||
}); | ||
|
||
// THEN it should include the AWS_REGION env variable | ||
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', { | ||
NetworkMode: ecs.NetworkMode.AWS_VPC, | ||
ContainerDefinitions: [{ | ||
Name: 'some-container', | ||
Image: 'amazon/amazon-ecs-sample', | ||
Memory: 512, | ||
Environment: [{ | ||
Name: 'SOME_VARIABLE', | ||
Value: 'some-value', | ||
}, { | ||
Name: 'AWS_REGION', | ||
Value: { | ||
Ref: 'AWS::Region', | ||
}, | ||
}], | ||
}], | ||
}); | ||
|
||
// GIVEN HOST network mode | ||
const anotherStack = new cdk.Stack(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case should be separated into another |
||
const anotherTaskDefiniton = new ecs.Ec2TaskDefinition(anotherStack, 'Ec2TaskDef', { | ||
networkMode: ecs.NetworkMode.HOST, | ||
}); | ||
anotherTaskDefiniton.addContainer('some-container', { | ||
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'), | ||
memoryLimitMiB: 512, | ||
environment: { | ||
SOME_VARIABLE: 'some-value', | ||
}, | ||
}); | ||
|
||
// THEN it should add in any env variables | ||
Template.fromStack(anotherStack).hasResourceProperties('AWS::ECS::TaskDefinition', { | ||
NetworkMode: ecs.NetworkMode.HOST, | ||
ContainerDefinitions: [{ | ||
Name: 'some-container', | ||
Image: 'amazon/amazon-ecs-sample', | ||
Memory: 512, | ||
Environment: [{ | ||
Name: 'SOME_VARIABLE', | ||
Value: 'some-value', | ||
}], | ||
}], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('setting inferenceAccelerators', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's reuse the parent's class method