Configurer des sessions persistantes pour vos load balancers

Vous pouvez créer une politique de sessions persistantes pour lier la session d’un utilisateur à une machine virtuelle (VM) backend spécifique.

Cette politique peut reposer sur une durée spécifique, ou être contrôlée par une application de la VM. Pour en savoir plus, voir À propos des load balancers > Sessions persistantes.

Après avoir créé la politique, vous devez activer celle-ci pour qu’elle soit appliquée.

Créer ou activer une politique de sessions persistantes avec OSC CLI

Avant de commencer : Assurez-vous que votre load balancer a un listener pour le protocole HTTP ou HTTPS, car les sessions persistantes se configurent uniquement avec ces protocoles. Pour en savoir plus, voir Ajouter ou supprimer des listeners.

À ce jour, cette section est disponible en anglais uniquement.

The CreateLoadBalancerPolicy command creates a stickiness policy with sticky session lifetimes defined by the browser lifetime.
The created policy can be used with HTTP or HTTPS listeners only.
If this policy is implemented by a load balancer, this load balancer uses this cookie in all incoming requests to direct them to the specified backend server virtual machine (VM). If this cookie is not present, the load balancer sends the request to any other server according to its load-balancing algorithm.

You can also create a stickiness policy with sticky session lifetimes following the lifetime of an application-generated cookie.
Unlike the other type of stickiness policy, the lifetime of the special Load Balancer Unit (LBU) cookie follows the lifetime of the application-generated cookie specified in the policy configuration. The load balancer inserts a new stickiness cookie only when the application response includes a new application cookie.
The session stops being sticky if the application cookie is removed or expires, until a new application cookie is issued.

For more information, see About Load Balancers.

Request sample: Creating a load balancer policy based on browser
$ osc-cli api CreateLoadBalancerPolicy --profile "default" \
    --LoadBalancerName "example-lbu" \
    --PolicyName "example-browser-policy" \
    --PolicyType "load_balancer"
Request sample: Creating a load balancer policy based on application cookie
$ osc-cli api CreateLoadBalancerPolicy --profile "default" \
    --LoadBalancerName "example-lbu" \
    --PolicyName "example-app-policy" \
    --PolicyType "app" \
    --CookieName "example-cookie"

This command contains the following attributes that you need to specify:

  • CookieExpirationPeriod: (optional) The lifetime of the cookie, in seconds. If not specified, the default value of this parameter is 1, which means that the sticky session lasts for the duration of the browser session.

  • CookieName: (optional) The name of the application cookie used for stickiness. This parameter is required if you create a stickiness policy based on an application-generated cookie.

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • LoadBalancerName: The name of the load balancer for which you want to create a policy.

  • PolicyName: The unique name of the policy, with a maximum length of 32 alphanumeric characters and dashes (-).

  • PolicyType: The type of stickiness policy you want to create: app or load_balancer.

The CreateLoadBalancerPolicy command returns the following elements:

  • LoadBalancer: Information about the load balancer.

    • AccessLog: Information about access logs.

      • IsEnabled: If true, access logs are enabled for your load balancer. If false, they are not. If you set this to true in your request, the OsuBucketName parameter is required.

      • OsuBucketName: The name of the OOS bucket for the access logs.

      • OsuBucketPrefix: The path to the folder of the access logs in your OOS bucket (by default, the root level of your bucket).

      • PublicationInterval: The time interval for the publication of access logs in the OOS bucket, in minutes. This value can be either 5 or 60 (by default, 60).

    • ApplicationStickyCookiePolicies: The stickiness policies defined for the load balancer.

      • CookieName: The name of the application cookie used for stickiness.

      • PolicyName: The mnemonic name for the policy being created. The name must be unique within a set of policies for this load balancer.

    • BackendIps: One or more public IPs of backend VMs.

    • BackendVmIds: One or more IDs of backend VMs for the load balancer.

    • DnsName: The DNS name of the load balancer.

    • HealthCheck: Information about the health check configuration.

      • CheckInterval: The number of seconds between two requests (between 5 and 600 both included).

      • HealthyThreshold: The number of consecutive successful requests before considering the VM as healthy (between 2 and 10 both included).

      • Path: If you use the HTTP or HTTPS protocols, the request URL path.

      • Port: The port number (between 1 and 65535, both included).

      • Protocol: The protocol for the URL of the VM (HTTP | HTTPS | TCP | SSL).

      • Timeout: The maximum waiting time for a response before considering the VM as unhealthy, in seconds (between 2 and 60 both included).

      • UnhealthyThreshold: The number of consecutive failed requests before considering the VM as unhealthy (between 2 and 10 both included).

    • Listeners: The listeners for the load balancer.

      • BackendPort: The port on which the backend VM is listening (between 1 and 65535, both included).

      • BackendProtocol: The protocol for routing traffic to backend VMs (HTTP | HTTPS | TCP | SSL).

      • LoadBalancerPort: The port on which the load balancer is listening (between 1 and 65535, both included).

      • LoadBalancerProtocol: The routing protocol (HTTP | HTTPS | TCP | SSL).

      • PolicyNames: The names of the policies. If there are no policies enabled, the list is empty.

      • ServerCertificateId: The OUTSCALE Resource Name (ORN) of the server certificate. For more information, see Resource Identifiers > OUTSCALE Resource Names (ORNs).

    • LoadBalancerName: The name of the load balancer.

    • LoadBalancerStickyCookiePolicies: The policies defined for the load balancer.

      • CookieExpirationPeriod: The time period, in seconds, after which the cookie should be considered stale.
        If 1, the stickiness session lasts for the duration of the browser session.

      • PolicyName: The name of the stickiness policy.

    • LoadBalancerType: The type of load balancer. Valid only for load balancers in a Net.
      If LoadBalancerType is internet-facing, the load balancer has a public DNS name that resolves to a public IP.
      If LoadBalancerType is internal, the load balancer has a public DNS name that resolves to a private IP.

    • NetId: The ID of the Net for the load balancer.

    • PublicIp: (internet-facing only) The public IP associated with the load balancer.

    • SecuredCookies: Whether secure cookies are enabled for the load balancer.

    • SecurityGroups: One or more IDs of security groups for the load balancers. Valid only for load balancers in a Net.

    • SourceSecurityGroup: Information about the source security group of the load balancer, which you can use as part of your inbound rules for your registered VMs.
      To only allow traffic from load balancers, add a security group rule that specifies this source security group as the inbound source.

      • SecurityGroupAccountId: The account ID of the owner of the security group.

      • SecurityGroupName: The name of the security group.

    • Subnets: The ID of the Subnet in which the load balancer was created.

    • SubregionNames: The ID of the Subregion in which the load balancer was created.

    • Tags: One or more tags associated with the load balancer.

      • Key: The key of the tag, with a minimum of 1 character.

      • Value: The value of the tag, between 0 and 255 characters.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample: Creating a load balancer policy based on browser
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "LoadBalancer": {
    "Tags": [],
    "SourceSecurityGroup": {
      "SecurityGroupName": "default",
      "SecurityGroupAccountId": "123456789012"
    },
    "Subnets": [
      "subnet-12345678"
    ],
    "NetId": "vpc-12345678",
    "BackendVmIds": [],
    "ApplicationStickyCookiePolicies": [],
    "SecurityGroups": [
      "sg-12345678"
    ],
    "LoadBalancerType": "internet-facing",
    "AccessLog": {
      "PublicationInterval": 60,
      "IsEnabled": false
    },
    "DnsName": "example-lbu-123456789.eu-west-2.lbu.outscale.com",
    "HealthCheck": {
      "UnhealthyThreshold": 2,
      "Timeout": 5,
      "CheckInterval": 30,
      "Protocol": "TCP",
      "HealthyThreshold": 10,
      "Port": 80
    },
    "LoadBalancerStickyCookiePolicies": [
      {
        "PolicyName": "example-browser-policy",
        "CookieExpirationPeriod": 1
      }
    ],
    "SubregionNames": [
      "eu-west-2a"
    ],
    "Listeners": [
      {
        "BackendPort": 80,
        "BackendProtocol": "HTTP",
        "LoadBalancerPort": 80,
        "LoadBalancerProtocol": "HTTP"
      }
    ],
    "LoadBalancerName": "example-lbu"
  }
}
Result sample: Creating a load balancer policy based on application cookie
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "LoadBalancer": {
    "Tags": [],
    "SourceSecurityGroup": {
      "SecurityGroupName": "default",
      "SecurityGroupAccountId": "123456789012"
    },
    "Subnets": [
      "subnet-12345678"
    ],
    "NetId": "vpc-12345678",
    "BackendVmIds": [],
    "ApplicationStickyCookiePolicies": [
      {
        "PolicyName": "example-app-policy",
        "CookieName": "example-cookie"
      }
    ],
    "SecurityGroups": [
      "sg-12345678"
    ],
    "LoadBalancerType": "internet-facing",
    "AccessLog": {
      "PublicationInterval": 60,
      "IsEnabled": false
    },
    "DnsName": "example-lbu-123456789.eu-west-2.lbu.outscale.com",
    "HealthCheck": {
      "UnhealthyThreshold": 2,
      "Timeout": 5,
      "CheckInterval": 30,
      "Protocol": "TCP",
      "HealthyThreshold": 10,
      "Port": 80
    },
    "LoadBalancerStickyCookiePolicies": [],
    "SubregionNames": [
      "eu-west-2a"
    ],
    "Listeners": [
      {
        "BackendPort": 80,
        "BackendProtocol": "HTTP",
        "LoadBalancerPort": 80,
        "LoadBalancerProtocol": "HTTP"
      }
    ],
    "LoadBalancerName": "example-lbu"
  }
}

Créer ou activer une politique de sessions persistantes avec oapi-cli

Avant de commencer : Assurez-vous que votre load balancer a un listener pour le protocole HTTP ou HTTPS, car les sessions persistantes se configurent uniquement avec ces protocoles. Pour en savoir plus, voir Ajouter ou supprimer des listeners.

À ce jour, cette section est disponible en anglais uniquement.

The CreateLoadBalancerPolicy command creates a stickiness policy with sticky session lifetimes defined by the browser lifetime.
The created policy can be used with HTTP or HTTPS listeners only.
If this policy is implemented by a load balancer, this load balancer uses this cookie in all incoming requests to direct them to the specified backend server virtual machine (VM). If this cookie is not present, the load balancer sends the request to any other server according to its load-balancing algorithm.

You can also create a stickiness policy with sticky session lifetimes following the lifetime of an application-generated cookie.
Unlike the other type of stickiness policy, the lifetime of the special Load Balancer Unit (LBU) cookie follows the lifetime of the application-generated cookie specified in the policy configuration. The load balancer inserts a new stickiness cookie only when the application response includes a new application cookie.
The session stops being sticky if the application cookie is removed or expires, until a new application cookie is issued.

For more information, see About Load Balancers.

Request sample: Creating a load balancer policy based on browser
$ oapi-cli --profile "default" CreateLoadBalancerPolicy \
    --LoadBalancerName "example-lbu" \
    --PolicyName "example-browser-policy" \
    --PolicyType "load_balancer"
Request sample: Creating a load balancer policy based on application cookie
$ oapi-cli --profile "default" CreateLoadBalancerPolicy \
    --LoadBalancerName "example-lbu" \
    --PolicyName "example-app-policy" \
    --PolicyType "app" \
    --CookieName "example-cookie"

This command contains the following attributes that you need to specify:

  • CookieExpirationPeriod: (optional) The lifetime of the cookie, in seconds. If not specified, the default value of this parameter is 1, which means that the sticky session lasts for the duration of the browser session.

  • CookieName: (optional) The name of the application cookie used for stickiness. This parameter is required if you create a stickiness policy based on an application-generated cookie.

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • LoadBalancerName: The name of the load balancer for which you want to create a policy.

  • PolicyName: The unique name of the policy, with a maximum length of 32 alphanumeric characters and dashes (-).

  • PolicyType: The type of stickiness policy you want to create: app or load_balancer.

The CreateLoadBalancerPolicy command returns the following elements:

  • LoadBalancer: Information about the load balancer.

    • AccessLog: Information about access logs.

      • IsEnabled: If true, access logs are enabled for your load balancer. If false, they are not. If you set this to true in your request, the OsuBucketName parameter is required.

      • OsuBucketName: The name of the OOS bucket for the access logs.

      • OsuBucketPrefix: The path to the folder of the access logs in your OOS bucket (by default, the root level of your bucket).

      • PublicationInterval: The time interval for the publication of access logs in the OOS bucket, in minutes. This value can be either 5 or 60 (by default, 60).

    • ApplicationStickyCookiePolicies: The stickiness policies defined for the load balancer.

      • CookieName: The name of the application cookie used for stickiness.

      • PolicyName: The mnemonic name for the policy being created. The name must be unique within a set of policies for this load balancer.

    • BackendIps: One or more public IPs of backend VMs.

    • BackendVmIds: One or more IDs of backend VMs for the load balancer.

    • DnsName: The DNS name of the load balancer.

    • HealthCheck: Information about the health check configuration.

      • CheckInterval: The number of seconds between two requests (between 5 and 600 both included).

      • HealthyThreshold: The number of consecutive successful requests before considering the VM as healthy (between 2 and 10 both included).

      • Path: If you use the HTTP or HTTPS protocols, the request URL path.

      • Port: The port number (between 1 and 65535, both included).

      • Protocol: The protocol for the URL of the VM (HTTP | HTTPS | TCP | SSL).

      • Timeout: The maximum waiting time for a response before considering the VM as unhealthy, in seconds (between 2 and 60 both included).

      • UnhealthyThreshold: The number of consecutive failed requests before considering the VM as unhealthy (between 2 and 10 both included).

    • Listeners: The listeners for the load balancer.

      • BackendPort: The port on which the backend VM is listening (between 1 and 65535, both included).

      • BackendProtocol: The protocol for routing traffic to backend VMs (HTTP | HTTPS | TCP | SSL).

      • LoadBalancerPort: The port on which the load balancer is listening (between 1 and 65535, both included).

      • LoadBalancerProtocol: The routing protocol (HTTP | HTTPS | TCP | SSL).

      • PolicyNames: The names of the policies. If there are no policies enabled, the list is empty.

      • ServerCertificateId: The OUTSCALE Resource Name (ORN) of the server certificate. For more information, see Resource Identifiers > OUTSCALE Resource Names (ORNs).

    • LoadBalancerName: The name of the load balancer.

    • LoadBalancerStickyCookiePolicies: The policies defined for the load balancer.

      • CookieExpirationPeriod: The time period, in seconds, after which the cookie should be considered stale.
        If 1, the stickiness session lasts for the duration of the browser session.

      • PolicyName: The name of the stickiness policy.

    • LoadBalancerType: The type of load balancer. Valid only for load balancers in a Net.
      If LoadBalancerType is internet-facing, the load balancer has a public DNS name that resolves to a public IP.
      If LoadBalancerType is internal, the load balancer has a public DNS name that resolves to a private IP.

    • NetId: The ID of the Net for the load balancer.

    • PublicIp: (internet-facing only) The public IP associated with the load balancer.

    • SecuredCookies: Whether secure cookies are enabled for the load balancer.

    • SecurityGroups: One or more IDs of security groups for the load balancers. Valid only for load balancers in a Net.

    • SourceSecurityGroup: Information about the source security group of the load balancer, which you can use as part of your inbound rules for your registered VMs.
      To only allow traffic from load balancers, add a security group rule that specifies this source security group as the inbound source.

      • SecurityGroupAccountId: The account ID of the owner of the security group.

      • SecurityGroupName: The name of the security group.

    • Subnets: The ID of the Subnet in which the load balancer was created.

    • SubregionNames: The ID of the Subregion in which the load balancer was created.

    • Tags: One or more tags associated with the load balancer.

      • Key: The key of the tag, with a minimum of 1 character.

      • Value: The value of the tag, between 0 and 255 characters.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample: Creating a load balancer policy based on browser
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "LoadBalancer": {
    "Tags": [],
    "SourceSecurityGroup": {
      "SecurityGroupName": "default",
      "SecurityGroupAccountId": "123456789012"
    },
    "Subnets": [
      "subnet-12345678"
    ],
    "NetId": "vpc-12345678",
    "BackendVmIds": [],
    "ApplicationStickyCookiePolicies": [],
    "SecurityGroups": [
      "sg-12345678"
    ],
    "LoadBalancerType": "internet-facing",
    "AccessLog": {
      "PublicationInterval": 60,
      "IsEnabled": false
    },
    "DnsName": "example-lbu-123456789.eu-west-2.lbu.outscale.com",
    "HealthCheck": {
      "UnhealthyThreshold": 2,
      "Timeout": 5,
      "CheckInterval": 30,
      "Protocol": "TCP",
      "HealthyThreshold": 10,
      "Port": 80
    },
    "LoadBalancerStickyCookiePolicies": [
      {
        "PolicyName": "example-browser-policy",
        "CookieExpirationPeriod": 1
      }
    ],
    "SubregionNames": [
      "eu-west-2a"
    ],
    "Listeners": [
      {
        "BackendPort": 80,
        "BackendProtocol": "HTTP",
        "LoadBalancerPort": 80,
        "LoadBalancerProtocol": "HTTP"
      }
    ],
    "LoadBalancerName": "example-lbu"
  }
}
Result sample: Creating a load balancer policy based on application cookie
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "LoadBalancer": {
    "Tags": [],
    "SourceSecurityGroup": {
      "SecurityGroupName": "default",
      "SecurityGroupAccountId": "123456789012"
    },
    "Subnets": [
      "subnet-12345678"
    ],
    "NetId": "vpc-12345678",
    "BackendVmIds": [],
    "ApplicationStickyCookiePolicies": [
      {
        "PolicyName": "example-app-policy",
        "CookieName": "example-cookie"
      }
    ],
    "SecurityGroups": [
      "sg-12345678"
    ],
    "LoadBalancerType": "internet-facing",
    "AccessLog": {
      "PublicationInterval": 60,
      "IsEnabled": false
    },
    "DnsName": "example-lbu-123456789.eu-west-2.lbu.outscale.com",
    "HealthCheck": {
      "UnhealthyThreshold": 2,
      "Timeout": 5,
      "CheckInterval": 30,
      "Protocol": "TCP",
      "HealthyThreshold": 10,
      "Port": 80
    },
    "LoadBalancerStickyCookiePolicies": [],
    "SubregionNames": [
      "eu-west-2a"
    ],
    "Listeners": [
      {
        "BackendPort": 80,
        "BackendProtocol": "HTTP",
        "LoadBalancerPort": 80,
        "LoadBalancerProtocol": "HTTP"
      }
    ],
    "LoadBalancerName": "example-lbu"
  }
}

Créer ou activer une politique de sessions persistantes avec AWS CLI

Avant de commencer : Installez et configurez AWS CLI. Pour en savoir plus, voir Installer et configurer AWS CLI.

Créer une politique de sessions persistantes

Sessions persistantes reposant sur une durée

Avant de commencer : Assurez-vous que votre load balancer a un listener pour le protocole HTTP ou HTTPS, car les sessions persistantes se configurent uniquement avec ces protocoles. Pour en savoir plus, voir Ajouter ou supprimer des listeners.

Pour créer une politique de sessions persistantes reposant sur une durée, utilisez la commande create-lb-cookie-stickiness-policy en suivant cette syntaxe :

Exemple de requête
$ aws elb create-lb-cookie-stickiness-policy \
    --profile YOUR_PROFILE \
    --load-balancer-name LOAD_BALANCER_NAME \
    --policy-name POLICY_NAME \
    --cookie-expiration-period 3600 \
    --endpoint https://lbu.eu-west-2.outscale.com

Cette commande contient les attributs suivants que vous devez spécifier :

  • (optionnel) profile : Le profil nommé que vous voulez utiliser, créé pendant la configuration d’AWS CLI. Pour en savoir plus, voir Installer et configurer AWS CLI.

  • load-balancer-name : Le nom du load balancer pour lequel vous voulez configurer la politique.

  • policy-name : Un nom pour la politique.

    Ce nom peut contenir des caractères alphanumériques et des tirets (-) uniquement.

  • (optionnel) cookie-expiration-period : La durée de la session persistante, en secondes.

    Cette durée doit être supérieure à 0. Si cette durée est égale à 1 (valeur par défaut), la session persistante dure le temps de la session de navigateur.

  • endpoint : Le endpoint correspondant à la Région à laquelle vous voulez envoyer la requête. Pour en savoir plus, voir Installer et configurer AWS CLI.

Sessions persistantes contrôlées par une application

La politique de sessions persistantes reposant sur une durée est créée pour le load balancer spécifié.

Avant de commencer : Assurez-vous que votre load balancer a un listener pour le protocole HTTP ou HTTPS, car les sessions persistantes se configurent uniquement avec ces protocoles. Pour en savoir plus, voir Ajouter ou supprimer des listeners.

Pour créer une politique de sessions persistantes contrôlée par une application, utilisez la commande create-app-cookie-stickiness-policy en suivant cette syntaxe :

Exemple de requête
$ aws elb create-app-cookie-stickiness-policy \
    --profile YOUR_PROFILE \
    --load-balancer-name LOAD_BALANCER_NAME \
    --policy-name POLICY_NAME \
    --cookie-name COOKIE_NAME \
    --endpoint https://lbu.eu-west-2.outscale.com

Cette commande contient les attributs suivants que vous devez spécifier :

  • (optionnel) profile : Le profil nommé que vous voulez utiliser, créé pendant la configuration d’AWS CLI. Pour en savoir plus, voir Installer et configurer AWS CLI.

  • load-balancer-name : Le nom du load balancer pour lequel vous voulez configurer la politique.

  • policy-name : Un nom pour la politique.

    Ce nom peut contenir des caractères alphanumériques et des tirets (-) uniquement.

  • cookie-name : Le nom du cookie d’application utilisé pour la persistance.

  • endpoint : Le endpoint correspondant à la Région à laquelle vous voulez envoyer la requête. Pour en savoir plus, voir Installer et configurer AWS CLI.

La politique de sessions persistantes contrôlée par une application est créée pour le load balancer spécifié.

Activer une politique de sessions persistantes

Pour activer la politique de sessions persistantes, utilisez la commande set-load-balancer-policies-of-listener en suivant cette syntaxe :

Exemple de requête
$ aws elb set-load-balancer-policies-of-listener \
    --profile YOUR_PROFILE \
    --load-balancer-name LOAD_BALANCER_NAME \
    --load-balancer-port 80 \
    --policy-names POLICY_NAME \
    --endpoint https://lbu.eu-west-2.outscale.com

Cette commande contient les attributs suivants que vous devez spécifier :

  • (optionnel) profile : Le profil nommé que vous voulez utiliser, créé pendant la configuration d’AWS CLI. Pour en savoir plus, voir Installer et configurer AWS CLI.

  • load-balancer-name : Le nom du load balancer pour lequel pour voulez activer la politique.

  • load-balancer-port : Le port externe du load balancer (entre 1 et 65535, tous deux inclus).

  • policy-names : Le nom de la politique que vous voulez activer pour le listener.

    • Une seule politique peut être active à la fois. Si une politique est déjà activée pour le listener, la nouvelle politique remplace l’ancienne.

    • Pour désactiver une politique activée, spécifiez [].

  • endpoint : Le endpoint correspondant à la Région à laquelle vous voulez envoyer la requête. Pour en savoir plus, voir Installer et configurer AWS CLI.

La politique de sessions persistantes est activée pour le load balancer spécifié.

Pages connexes

Méthodes API correspondantes

AWS™ et Amazon Web Services™ sont des marques de commerce d’Amazon Technologies, Inc. ou de ses affiliées aux États-Unis et/ou dans les autres pays.