如果您使用的是 aws CDK,以下应该可以工作
const autoscaling = require('@aws-cdk/aws-autoscaling');
const custom_resource = require('@aws-cdk/custom-resources');
function stopAsgScaling(stack, asgName) {
return new custom_resource.AwsCustomResource(stack, 'MyAwsCustomResource', {
policy: custom_resource.AwsCustomResourcePolicy.fromSdkCalls({
resources: custom_resource.AwsCustomResourcePolicy.ANY_RESOURCE
}),
onCreate: {
service: 'AutoScaling',
action: 'suspendProcesses',
parameters: {
AutoScalingGroupName: asgName,
},
physicalResourceId: custom_resource.PhysicalResourceId.of(
'InvokeLambdaResourceId1234'),
},
onDelete: {
service: 'AutoScaling',
action: 'resumeProcesses',
parameters: {
AutoScalingGroupName: asgName,
},
physicalResourceId: custom_resource.PhysicalResourceId.of(
'InvokeLambdaResourceId1234'),
},
})
};
class MainStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const autoScalingGroupName = "my-asg"
const myAsg = new autoscaling.AutoScalingGroup(
this,
autoScalingGroupName,
{autoScalingGroupName: autoScalingGroupName})
const acr = stopAsgScaling(this, autoScalingGroupName);
acr.node.addDependency(myAsg);
}
};