To run a CLI command from within an Amazon Elastic Compute Cloud (Amazon EC2) instance or an Amazon Elastic Container Service (Amazon ECS) container, you can use an IAM role attached to the instance profile or the container. If you specify no profile or set no environment variables, that role is used directly. This enables you to avoid storing long-lived access keys on your instances. You can also use those instance or container roles only to get credentials for another role. To do this, you use credential_source (instead of source_profile) to specify how to find the credentials. The credential_source attribute supports the following values:
Environment – Retrieves the source credentials from environment variables.
Ec2InstanceMetadata – Uses the IAM role attached to the Amazon EC2 instance profile.
EcsContainer – Uses the IAM role attached to the Amazon ECS container.
-
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.htmlUn container pour émuler en local l'api metadata et ainsi endosser un role
https://github.com/awslabs/amazon-ecs-local-container-endpoints
-
https://aws.amazon.com/blogs/compute/a-guide-to-locally-testing-containers-with-amazon-ecs-local-endpoints-and-docker-compose/Gérer des resources aws avec un controller kube fourni par aws
-
https://aws.amazon.com/blogs/containers/aws-controllers-for-kubernetes-ack/Another simple solution would be to write a custom MIDDLEWARE which will give the response to ELB before the ALLOWED_HOSTS is checked. So now you don't have to load ALLOWED_HOSTS dynamically.
The middleware can be as simple as:
project/app/middleware.py
from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin
class HealthCheckMiddleware(MiddlewareMixin):
def process_request(self, request):
if request.META["PATH_INFO"] == "/ping/":
return HttpResponse("pong")
settings.py
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'app.middleware.HealthCheckMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
...
]
Django Middleware reference https://docs.djangoproject.com/en/dev/topics/http/middleware/
-
https://stackoverflow.com/questions/35858040/django-allowed-hosts-for-amazon-elbhttps://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scaling-target-tracking.html
https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-instance-monitoring.html#enable-as-instance-metrics
https://www.terraform.io/docs/providers/aws/r/appautoscaling_policy.html
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-auto-scaling.html
-
https://aws.amazon.com/fr/about-aws/whats-new/2017/07/application-load-balancer-adds-support-for-new-requestcountpertarget-cloudwatch-metric/