How to get the MD5 sum of a string using Python

If you need to get the MD5 sum of a string using Python, then you can do the following. Step 1 Firstly, we need to use the hashlib module: 1 import hashlib Step 2 Now make sure that the input string is encoded correctly. 1 your_input = "this is your input string".encode('utf-8') Step 3 Finally use the md5 function of the hashlib module, and get the hexdigest() value from it:

[Solved] TypeError: datetime Not JSON Serializable

If you get the following error: TypeError: Object of type datetime is not JSON serializable ..then you can solve it by using this trick: 1 json.dumps(your_dict, indent=4, sort_keys=True, default=str)

How to Return a List of All AWS Lambda Function Names in CLI

If you would like to list all AWS Lambda Function Names in your CLI using the AWS CLI, then you can do this: Get a List of all Lambda Functions 1 aws lambda list-functions However, note that this will return a potentially large JSON payload back to your CLI. So what if you only want a list of the function names themselves? You can couple the AWS command above, with the jq command as follows:

How much faster is Python code?

The speed of Python code compared to other programming languages depends on a variety of factors, such as the specific task being performed, the libraries and frameworks used, the quality of the code implementation, and the hardware on which the code is executed. In general, Python is an interpreted language, which means that code is executed line-by-line by an interpreter, rather than being compiled into machine code beforehand. This can make Python code slower than compiled languages like C or C++ for some tasks.

Zip & Encode Dict to String & Back in Python

If you have a Python dictionary, and want to encode it as a string and zip it to save space, perhaps for passing a dictionary through as an environment variable or similar, then you can do the following Zip then Encode / Decode then Unzip Functions 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import json, gzip, base64 from io import BytesIO def _zip_then_encode(data: dict) -> str: """Gzip and base64 encode a dictionary""" if type(data) !

What Categories of Websites are there?

There are many different categories of websites, but here are some of the most common: E-commerce websites: These websites sell products or services online. Examples include Amazon, eBay, and Etsy. News websites: These websites provide up-to-date news and information on a variety of topics. Examples include CNN, BBC, and The New York Times. Blogging websites: These websites are used for personal or business blogs. Examples include WordPress, Blogger, and Medium.

How to Generate a Random Number between 2 numbers in Python

If you need to generate a random number between two (2) numbers in Python, then you can make use of the random module. First, import the module: 1 import random Then you can use it like this: 1 random.randint(0, 255) Another option is to use randrange and uniform as follows: 1 2 3 4 5 6 7 from random import randrange, uniform # randrange gives you an integral value irand = randrange(0, 10) # uniform gives you a floating-point value frand = uniform(0, 10)

How to Install AWS SAM CLI on Mac

If you need to install AWS SAM CLI on a Mac, then the easiest option is to use Homebrew with the following commands: 1 2 brew tap aws/tap brew install aws-sam-cli Now you can validate the installation as follows: 1 sam --version

How to count the amount of rows in MariaDB fast

If you need to find the fastest way to count the number of rows in a massive MariaDB, or MySQL table, then you can do the following instead of performing a select count() query: 1 show table status like '<TABLE_NAME>' This will provide you with a table of information about the table statistics, including the amount of rows.

How to find the Product of Consecutive Fib Numbers in Python

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, … This is the Van Eck’s Sequence. Let’s go through it step by step. Term 1: The first term is 0. Term 2: Since we haven’t seen 0 before, the second term is 0. Term 3: Since we had seen a 0 before, one step back, the third term is 1 Term 4: Since we haven’t seen a 1 before, the fourth term is 0 Term 5: Since we had seen a 0 before, two steps back, the fifth term is 2.

How to Solve Van Eck's Sequence in Python

0, 0, 1, 0, 2, 0, 2, 2, 1, 6, 0, 5, 0, 2, 6, 5, 4, 0, 5, 3, 0, 3, … This is the Van Eck’s Sequence. Let’s go through it step by step. Term 1: The first term is 0. Term 2: Since we haven’t seen 0 before, the second term is 0. Term 3: Since we had seen a 0 before, one step back, the third term is 1 Term 4: Since we haven’t seen a 1 before, the fourth term is 0 Term 5: Since we had seen a 0 before, two steps back, the fifth term is 2.

How to Solve: Help the Bookseller Challenge in Python

A bookseller has lots of books classified in 26 categories labeled A, B, … Z. Each book has a code c of 3, 4, 5 or more characters. The 1st character of a code is a capital letter which defines the book category. In the bookseller’s stocklist each code c is followed by a space and by a positive integer n (int n >= 0) which indicates the quantity of books of this code in stock.

How to solve AWS MediaPackage PackagingGroup Quota Limit

If you are using AWS Elemental MediaPackage and hit the following error, then you need to either do one of the following: Error: error waiting for CloudFormation Stack (arn:aws:cloudformation:eu-west-1:800417762774:stack/dev-MediaPackage-Vod-1/511fc7a0-a092-11ed-b853-068baf6ac251) create: failed to create CloudFormation stack, delete requested (DELETE_COMPLETE): ["The following resource(s) failed to create: [PackagingGroup]. Delete requested by user." "Resource handler returned message: \"Limit exceeded for resource of type 'AWS::MediaPackage::PackagingGroup'. Reason: You reached the quota for resource=PackagingGroup. Delete the resources that you don?

How to Run Cdk Bootstrap

To bootstrap an AWS CDK environment, you simply need to do the following: 1 npx aws-cdk bootstrap …for each environment that you would like the CD to operate within. This will deploy all the required prerequisites to the AWS account, such as the: An Amazon S3 bucket for storing files and IAM roles that grant permissions needed to perform deployments. The required resources are defined in an AWS CloudFormation stack, called the bootstrap stack, which is usually named CDKToolkit.

How to Get Account Number from AWS Lambda

If you need to get the current Account Number, or Account ID from within a Lambda execution, then you can access invoked_function_arn from the context and return the associated value as follows: 1 aws_account_id = context.invoked_function_arn.split(":")[4]

Summary of the Frequently Used AWS STS API calls

AssumeRole – is useful for allowing existing IAM users to access AWS resources that they don’t already have access to. For example, the user might need access to resources in another AWS account. It is also useful as a means to temporarily gain privileged access—for example, to provide multi-factor authentication (MFA). You must call this API using existing IAM user credentials. AssumeRoleWithWebIdentity – returns a set of temporary security credentials for federated users who are authenticated through a public identity provider.

Understanding Locking and Conditional Writes in AWS DynamoDB

Optimistic locking is a strategy to ensure that the client-side item that you are updating (or deleting) is the same as the item in DynamoDB. Optimistic concurrency depends on checking a value upon save to ensure that it has not changed. If you use this strategy, then your database writes are protected from being overwritten by the writes of others — and vice-versa. By default, the DynamoDB write operations (PutItem, UpdateItem, DeleteItem) are unconditional: each of these operations will overwrite an existing item that has the specified primary key.

AWS CodeDeploy Deployment Type Options

CodeDeploy provides two (2) deployment type options: Option 1 – In-place Deployment In-place deployment: The application on each instance in the deployment group is stopped, the latest application revision is installed, and the new version of the application is started and validated. You can use a load balancer so that each instance is deregistered during its deployment and then restored to service after the deployment is complete. Only deployments that use the EC2/On-Premises compute platform can use in-place deployments.

Defining Amazon ECS Task Placement Strategies

Amazon ECS supports the following task placement strategies: binpack – Place tasks based on the least available amount of CPU or memory. This minimizes the number of instances in use. random – Place tasks randomly. spread – Place tasks evenly based on the specified value. Accepted values are attribute key-value pairs, instanceId, or host.

Deployment methods in AWS Elastic Beanstalk

– All at once – Deploy the new version to all instances simultaneously. All instances in your environment are out of service for a short time while the deployment occurs. – Rolling – Deploy the new version in batches. Each batch is taken out of service during the deployment phase, reducing your environment’s capacity by the number of instances in a batch. – Rolling with additional batch – Deploy the new version in batches, but first launch a new batch of instances to ensure full capacity during the deployment process.