Managing FastAPI Projects with Poetry: A Step-by-Step Guide

Image
This guide will walk you through how to use Poetry to manage dependencies and structure your project in FastAPI . It includes detailed explanations of Poetry's core concepts and commands to help prevent issues that can arise during team collaboration and deployment. 1. What is Poetry? Poetry is a dependency management and packaging tool for Python. It goes beyond simply installing libraries by allowing you to clearly declare the dependencies your project needs and ensuring that all developers on the project have the same library versions. Clarity in Dependency Management : Explicitly manage your project's basic information and required libraries through the pyproject.toml file. Reproducible Builds : By locking all dependency versions in the poetry.lock file, it fundamentally prevents "it works on my machine" problems. Integrated Development Environment : It automatically creates and manages isolated virtual environments for each project and handles mo...

AWS SAM Template: How to Properly Define Inline IAM Policies

AWS Serverless Application Model (SAM) is a powerful framework for defining serverless resources like Lambda functions. One commonly misunderstood part of SAM templates is the Policies section under AWS::Serverless::Function.

I used to write YAML files without ever including the Version field, so I habitually left it out in the Policies section as well — this caused unexpected error when deploying, and it took me quite a while to figure out what was wrong and fix the problem.

Incorrect: Using Only "- Statement:"

Policies:
  - Statement:
      - Effect: Allow
        Action:
          - transcribe:GetMedicalTranscriptionJob
        Resource: "*"

This will result in errors like:

Invalid ARN: Could not be parsed!
Template format error: Every policy must contain a Version field

Correct: Include Full Policy Document

Policies:
  - Version: '2012-10-17'
    Statement:
      - Effect: Allow
        Action:
          - transcribe:GetMedicalTranscriptionJob
        Resource: "*"

IAM policies always require a complete structure with a Version and a Statement array:

{
  "Version": "2012-10-17",
  "Statement": [ ... ]
}

Since AWS SAM directly expects this structure, omitting the Version will cause deployment errors.

Why 'Version' Is Required in SAM Inline Policies

  • The AWS SAM Developer Guide does not contain an explicit statement such as "When defining an inline policy in the Policies section, you must include Version: '2012-10-17'."
  • However, since the expected input for the Policies property is a standard IAM policy document, which includes the Version: '2012-10-17' field, it is reasonable to infer that including this field is the correct approach.

Comments

Popular posts from this blog

Resolving Key Exchange Failure When Connecting with SecureCRT to OpenSSH

SecureCRT] How to Back Up and Restore SecureCRT Settings on Windows

How to Set Up Vaultwarden (Bitwarden) on Synology NAS (Best Free Alternative to LastPass)