How to Enable ContainerInsights on AWS ECS from the AWS CLI

If you need to enable Container Insights for an ECS cluster, by using the AWS CLI, then you can do the following: 1 2 3 4 aws ecs update-cluster-settings --cluster <cluster-name> --settings name=containerInsights,value=enabled --region <aws_region>

AppMesh and ECS with Imported ACM certificates on Envoy Sidecar through EFS

Summary This guide showcases the ability to use imported certificates from a third party provider (e.g. Venafi) in ACM, mount them in EFS and use them as trusted sources on Envoy sidecars with applications running in ECS. AppMesh is used as a passthrough with TLS termination occurring on the application container layer. Prerequisites and limitations Prerequisites A certificate that contains the chain of domains required for the fronted service and micro-services needed.

How to Increase the disk size on a Cloud9 instance

If you need to increase the disk size of a Cloud9 instance, you can run the following script directly from the terminal in Cloud9: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 pip3 install --user --upgrade boto3 export instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) python3 -c "import boto3 import os from botocore.exceptions import ClientError ec2 = boto3.

How to Get the Instance Profile attached to an AWS EC2

If you need to get the IAM Role information from the attached EC2 role directly, you can do the following: 1 2 IAM_ROLE=$(curl -s 169.254.169.254/latest/meta-data/iam/info | \ jq -r '.InstanceProfileArn' | cut -d'/' -f2)

How to Create an AWS ECR Repository in AWS CLI

If you need to create an Elastic Container Registry (ECR) Repository from the AWS CLI, you can do the following: 1 2 3 4 aws ecr create-repository \ --repository-name <repo-name> \ --image-scanning-configuration scanOnPush=true \ --region ${AWS_REGION}

How to Scale Out an AWS ECS Service

When you create the Amazon ECS service, it includes three Amazon ECS task replicas. You can see this by using the describe-services command, which returns three. Use the update-service command to scale the service to five tasks. Re-run the describe-services command to see the updated five. Step 1 – Query the desired count 1 2 3 4 aws ecs describe-services \ --cluster fargate-getting-started \ --services nginx-service \ --query 'services[0].desiredCount' Output: 3

How to Retrieve AWS ECS Cluster Information

For more information about the Amazon ECS cluster, run the following command. You will find the number of running tasks, capacity providers, and more. 1 aws ecs describe-clusters --cluster <your-fargate-cluster> Sample output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 { "clusters": [ { "clusterArn": "arn:aws:ecs:us-east-2:123456789012:cluster/<your-fargate-cluster>", "clusterName": "fargate-getting-started", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 3, "pendingTasksCount": 0, "activeServicesCount": 1, "statistics": [], "tags": [], "settings": [], "capacityProviders": [ "FARGATE", "FARGATE_SPOT" ], "defaultCapacityProviderStrategy": [] } ], "failures": [] }

Types of communication in Amazon EKS

There are multiple types of communication in Amazon EKS environments. Lines of communication include the following: Interpod communication between containers Communication between pods on the same node or pods on different nodes Ingress connections from outside the cluster In some cases, the default Kubernetes methods are used. In other cases, specifically inter-node communication and ingress methods specific to Amazon EKS are used. Intrapod communication Containers in a pod share a Linux namespace and can communicate with each other using localhost.

[Solved] Read timeout on endpoint URL: “https://lambda.[region].amazonaws.com/2015-03-31/functions/[function-name]/invocations”

If you get the following error: 1 Read timeout on endpoint URL: "https://lambda.<region>.amazonaws.com/2015-03-31/functions/<function-name>/invocations" Then you are probably trying to use the aws cli to invoke an AWS Lambda function and it is timing out. Other than making sure to set the Lambda execution time to something much higher than it is, you also need to make sure to specify the aws cli --cli-read-timeout argument to something that will cover the execution time.

How to Remove a Passphrase from Certificate Key

If you have a Certificate Key that includes a Passphrase and you need to remove it, potentially to use it with AWS App Mesh, then you can do the following: How to Remove a Passphrase using OpenSSL Locate the Private Key Run the following command: open ssl rsa -in <original.key> -out <new.key> Enter the original passphrase for the existing key The output file <new.key> will now be unencrypted How to Verify if the Passphrase has been removed Open the file in a text editor and check the headers.

How to get Python logger to Print to std out

If you use Python’s logger as follows: 1 2 3 import logging logger = logging.getLogger() logger.setLevel(logging.DEBUG) # or logging.INFO Perhaps you want to get it to print to Standard Output (stdout), then you can do the following: Setup Logger to print to Standard Output 1 2 3 4 5 6 7 8 9 10 11 import logging logger = logging.getLogger() # logger.setLevel(logging.INFO) logger.setLevel(logging.DEBUG) handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.

How to Convert a String to an Integer in C

If you need to convert a String to an Integer in C, then you can do one of the following: Option 1 – Use atoi() int atoi(const char *str); You can do something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h> #include <stdlib.h> #include <string.h> int main (void) { int value; char str[20]; strcpy(str,"123"); value = atoi(str); printf("String value = %s, Int value = %d\n", str, value); return(0); } Option 2 – Use strtol() long int strtol(const char *string, char **laststr,int basenumber);

How to Convert an Integer to a String in C

If you need to convert an Integer to a String in C, then you can do one of the following: Option 1 – Use sprintf() int sprintf(char *str, const char *format, [arg1, arg2, ... ]); You can do something like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <stdio.h> int main(void) { int number; char text[20]; printf("Enter a number: "); scanf("%d", &number); sprintf(text, "%d", number); printf("\nYou have entered: %s", text); return 0; } Option 2 – Use itoa() char* itoa(int num, char * buffer, int base)

How to append to an Array in Elasticsearch using elasticsearch-py

If you are using the Official ElasticSearch Python library (Docs), and you want to create an index: 1 2 3 4 5 6 7 doc = { "something": "123a", "somethingelse": "456b", "timestamp": datetime.now(), "history": [] } es.index(index="someindex", doc_type="somedoctype", id="someid", body=doc) You can append items to the history each time, instead of overriding them, like this: 1 2 3 4 5 6 7 8 9 10 es.update(index="someindex", doc_type="somedoctype", id="someid", body={ "script" : { "source": "ctx.

How to Copy Text to the Clipboard in Python

If you need to Copy Text to the Clipboard using your Python application code, then you can do the following: Option 1 – Using pyperclip First install the pyperclip package, using pip: 1 pip install pyperclip Now you can run the following code: 1 2 3 4 5 6 7 8 import pyperclip as pc a1 = "This text will now be in your clipboard" pc.copy(a1) a2 = pc.paste() print(a2) print(type(a2)) Option 2 – Using pyperclip3 This version is similar to the first option above, except it copies all the data into bytes.

How to Read a PDF file in Python

If you need to read a PDF (Portable Document Format) file in your Python code, then you can do the following: Option 1 – Using PyPDF2 1 2 3 4 5 from PyPDF2 import PDFFileReader temp = open('your_document.pdf', 'rb') PDF_read = PDFFileReader(temp) first_page = PDF_read.getPage(0) print(first_page.extractText()) Option 2 – Using PDFplumber 1 2 3 4 import PDFplumber with PDFplumber.open("your_document.PDF") as temp: first_page = temp.pages[0] print(first_page.extract_text()) Option 3 – Using textract 1 2 import textract PDF_read = textract.

How to Convert HEX to RBG in Python

If you need to convert HEX (Hexadecimal) to RGB (Red-Green-Blue) in your Python code, then you can do the following: Option 1 – Using the PIL library 1 2 3 from PIL import ImageColor hex = input('Enter HEX value: ') ImageColor.getcolor(hex, "RGB") Option 2 – Using a custom solution 1 2 hex = input('Enter HEX value: ').lstrip('#') print('RGB value =', tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)))

How to Refer to a Null Object in Python

If you need to refer to a Null Object in your Python code, then you can do the following. It is important to note that Python does not have a Null type, instead Python refers to not set objects or variables as None. We can use the is keyword to check if an object or variable has the type of None. 1 2 3 4 5 object_name = None print(object_name is None) object_name = ' some_value' print(object_name is None)

How to Convert Bytearray to String in Python

If you need to convert a Bytearray to a String in Python, then you can do the following: Option 1 – Using bytes() 1 2 3 b = bytearray("test", encoding="utf-8") str1 = bytes(b) print(str1) Option 2 – Using bytearray.decode() 1 2 3 b = bytearray("test", encoding="utf-8") str1 = b.decode() print(str1)

How to get the Hostname in Python

If you need to get the Hostname in your Python application, then you can do the following: Option 1 – Using gethostname() 1 2 import socket print(socket.gethostname()) Option 2 – Using the platform module 1 2 import platform print (platform.node()) Option 3 – Using os.uname() 1 2 3 import os hname = os.uname() print(hname)