createProtection method
Enables AWS Shield Advanced for a specific AWS resource. The resource can be an Amazon CloudFront distribution, Elastic Load Balancing load balancer, AWS Global Accelerator accelerator, Elastic IP Address, or an Amazon Route 53 hosted zone.
You can add protection to only a single resource with each CreateProtection request. If you want to add protection to multiple resources at once, use the AWS WAF console. For more information see Getting Started with AWS Shield Advanced and Add AWS Shield Advanced Protection to more AWS Resources.
May throw InternalErrorException. May throw InvalidResourceException. May throw InvalidOperationException. May throw LimitsExceededException. May throw ResourceAlreadyExistsException. May throw OptimisticLockException. May throw ResourceNotFoundException.
Parameter name
:
Friendly name for the Protection
you are creating.
Parameter resourceArn
:
The ARN (Amazon Resource Name) of the resource to be protected.
The ARN should be in one of the following formats:
-
For an Application Load Balancer:
arn:aws:elasticloadbalancing:region:account-id:loadbalancer/app/load-balancer-name/load-balancer-id
-
For an Elastic Load Balancer (Classic Load Balancer):
arn:aws:elasticloadbalancing:region:account-id:loadbalancer/load-balancer-name
-
For an AWS CloudFront distribution:
arn:aws:cloudfront::account-id:distribution/distribution-id
-
For an AWS Global Accelerator accelerator:
arn:aws:globalaccelerator::account-id:accelerator/accelerator-id
-
For Amazon Route 53:
arn:aws:route53:::hostedzone/hosted-zone-id
-
For an Elastic IP address:
arn:aws:ec2:region:account-id:eip-allocation/allocation-id
Implementation
Future<CreateProtectionResponse> createProtection({
required String name,
required String resourceArn,
}) async {
ArgumentError.checkNotNull(name, 'name');
_s.validateStringLength(
'name',
name,
1,
128,
isRequired: true,
);
ArgumentError.checkNotNull(resourceArn, 'resourceArn');
_s.validateStringLength(
'resourceArn',
resourceArn,
1,
2048,
isRequired: true,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSShield_20160616.CreateProtection'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'Name': name,
'ResourceArn': resourceArn,
},
);
return CreateProtectionResponse.fromJson(jsonResponse.body);
}