<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Python on anthony lukach</title><link>https://alukach.com/tags/python/</link><description>Recent content in Python on anthony lukach</description><generator>Hugo -- 0.128.0</generator><language>en-us</language><lastBuildDate>Thu, 08 Sep 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://alukach.com/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Auto-assume an IAM role before running a command</title><link>https://alukach.com/posts/with-role-command/</link><pubDate>Thu, 08 Sep 2022 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/with-role-command/</guid><description>A convenience function to assume a IAM Role via STS before running a command.
Add the following to your ~/.zshrc (or equivalent) file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 function with-role { readonly role_arn=${1:?&amp;#34;The role_arn must be specified.&amp;#34;} env -S $( aws sts assume-role \ --role-arn ${role_arn} \ --role-session-name ${USER} \ | \ jq -r &amp;#39;.Credentials | &amp;#34; AWS_ACCESS_KEY_ID=\(.AccessKeyId) AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey) AWS_SESSION_TOKEN=\(.SessionToken) &amp;#34;&amp;#39; ) ${@:2} } This assumes that you have both the AWS CLI and jq installed.</description></item><item><title>Type-based message processing with Pydantic</title><link>https://alukach.com/posts/message-processing-with-pydantic/</link><pubDate>Fri, 05 Aug 2022 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/message-processing-with-pydantic/</guid><description>When building systems to process messages, it&amp;rsquo;s not unlikely to find yourself in a situation where you need to process a number of inputted heterogeneous messages (i.e. messages of varying shapes/types). For example, consider a situation where you are processing messages from an SQS queue via a Lambda function. This post attempts to highlight how this can be achieved in a clean and elegant manner by utilizing Pydantic, Python&amp;rsquo;s typing system, and some helpers from the Python standard library.</description></item><item><title>Securing FastAPI with JWKS (AWS Cognito, Auth0)</title><link>https://alukach.com/posts/fastapi-rs256-jwt/</link><pubDate>Fri, 27 May 2022 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/fastapi-rs256-jwt/</guid><description>This post is a quick capture of how to easily secure your FastAPI with any auth provider that provides JWKS.
Background: RS256 RS256 is a signing algorithm used to generate and validate JSON Web Tokens (JWTs). Unlike the common HS256 algorithm that uses the same secret string to both generate and validate JWTs, RS256 uses a private key to generate JWTs and a separate public key for validating JWTs:
RS256 generates an asymmetric signature, which means a private key must be used to sign the JWT and a different public key must be used to verify the signature.</description></item><item><title>SSH tunnels in Python</title><link>https://alukach.com/posts/ssh-tunnels-in-python/</link><pubDate>Fri, 17 Sep 2021 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/ssh-tunnels-in-python/</guid><description>At times, a developer may need to access infrastructure not available on the public internet. A common example of this is accessing a database located in a private subnet, as described in the VPC Scenario docs:
Instances in the private subnet are back-end servers that don&amp;rsquo;t need to accept incoming traffic from the internet and therefore do not have public IP addresses; however, they can send requests to the internet using the NAT gateway.</description></item><item><title>Concurrent Python Example Script</title><link>https://alukach.com/posts/concurrent-python-example-script/</link><pubDate>Fri, 19 Feb 2021 13:42:21 -0700</pubDate><guid>https://alukach.com/posts/concurrent-python-example-script/</guid><description>Below is a very simple example of a script that I write and re-write more often than I would like to admit. It reads input data from a CSV and processes each row concurrently. A progress bar provides updates. Honestly, it&amp;rsquo;s pretty much just the concurrent.futures ThreadPoolExecutor example plus a progress bar.</description></item><item><title>Using CloudFront as a Reverse Proxy</title><link>https://alukach.com/posts/using-cloudfont-as-a-reverse-proxy/</link><pubDate>Fri, 02 Oct 2020 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/using-cloudfont-as-a-reverse-proxy/</guid><description>Alternate title: How to be master of your domain.
The basic idea of this post is to demonstrate how CloudFront can be utilized as a serverless reverse-proxy, allowing you to host all of your application&amp;rsquo;s content and services from a single domain. This minimizes a project&amp;rsquo;s TLD footprint while providing project organization and performance along the way.
Why Within large organizations, bureaucracy can make it a challenge to obtain a subdomain for a project.</description></item><item><title>How to generate a database URI from an AWS Secret</title><link>https://alukach.com/posts/database-uri-from-secret/</link><pubDate>Mon, 15 Jun 2020 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/database-uri-from-secret/</guid><description>A quick note about how to generate a database URI (or any other derived string) from an AWS SecretsManager SecretTargetAttachment (such as what&amp;rsquo;s provided via a RDS DatabaseInstance&amp;rsquo;s secret property).
1 2 3 4 5 6 7 8 9 10 11 db = rds.DatabaseInstance( # ... ) db_val = lambda field: db.secret.secret_value_from_json(field).to_string() task_definition.add_container( environment=dict( # ... PGRST_DB_URI=f&amp;#34;postgres://{db_val(&amp;#39;username&amp;#39;)}:{db_val(&amp;#39;password&amp;#39;)}@{db_val(&amp;#39;host&amp;#39;)}:{db_val(&amp;#39;port&amp;#39;)}/&amp;#34;, ), # ... )</description></item><item><title>Tips for working with a large number of files in S3</title><link>https://alukach.com/posts/tips-for-working-with-a-large-number-of-files-in-s3/</link><pubDate>Sat, 30 May 2020 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/tips-for-working-with-a-large-number-of-files-in-s3/</guid><description>I would argue that S3 is basically AWS&amp;rsquo; best service. It&amp;rsquo;s super cheap, it&amp;rsquo;s basically infinitely scalable, and it never goes down (except for when it does). Part of its beauty is its simplicity. You give it a file and a key to identify that file, you can have faith that it will store it without issue. You give it a key, you can have faith that it will return the file represented by that key, assuming there is one.</description></item><item><title>Boilerplate for S3 Batch Operation Lambda</title><link>https://alukach.com/posts/aws-s3-batch-operation-lambda-boilerplate/</link><pubDate>Fri, 20 Dec 2019 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/aws-s3-batch-operation-lambda-boilerplate/</guid><description>S3 Batch Operation provide a simple way to process a number of files stored in an S3 bucket with a Lambda function. However, the Lambda function must return particular Response Codes. Below is an example of a Lambda function written in Python that works with AWS S3 Batch Operations.</description></item><item><title>Parsing S3 Inventory CSV output in Python</title><link>https://alukach.com/posts/parsing-s3-inventory-output/</link><pubDate>Mon, 16 Dec 2019 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/parsing-s3-inventory-output/</guid><description>S3 Inventory is a great way to access a large number of keys in an S3 Bucket. Its output is easily parsed by AWS Athena, enabling queries across the key names (e.g. find all keys ending with .png)
However, sometimes you just need to list all of the keys mentioned in the S3 Inventory output (e.g. populating an SQS queue with every keyname mentioned in an inventory output). The following code is an example of doing such task in Python:</description></item><item><title>A PIL-friendly class for S3 objects</title><link>https://alukach.com/posts/pil-friendly-s3-file/</link><pubDate>Wed, 11 Dec 2019 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/pil-friendly-s3-file/</guid><description>Here&amp;rsquo;s a quick example of creating an file-like object in Python that represents an object on S3 and plays nicely with PIL. This ended up being overkill for my needs but I figured somebody might get some use out of it.</description></item><item><title>Natural Language Toolkit Notes</title><link>https://alukach.com/posts/nltk-notes/</link><pubDate>Sun, 25 Aug 2013 00:00:00 +0000</pubDate><guid>https://alukach.com/posts/nltk-notes/</guid><description>I&amp;rsquo;ve been experimenting with Python&amp;rsquo;s Natural Language Toolkit, following along with Steven Bird, Ewan Klein, and Edward Loper&amp;rsquo;s book &amp;ldquo;Natural Language Processing with Python &amp;mdash; Analyzing Text with the Natural Language Toolkit&amp;rdquo; (pdf version).
So far, the book&amp;rsquo;s been great. As I&amp;rsquo;m going through the book, I&amp;rsquo;ve been writing down notes relating to the book&amp;rsquo;s examples. I&amp;rsquo;ve made a Github repo to store these notes and experiments that I may be doing using the NLTK here.</description></item></channel></rss>