AWS SAM Translator is a Python library responsible for transforming AWS Serverless Application Model (SAM) templates into standard AWS CloudFormation templates. It is a core component used by the AWS SAM CLI and maintains a rapid release cadence, with updates often reflecting new SAM specification features and CloudFormation resource support. The current version is 1.108.0.
pip install aws-sam-translatorVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to parse a SAM template string, initialize the `Translator` class, and convert the SAM template into a standard CloudFormation template. In a real application, `managed_policy_map` and `globals` would be populated based on the SAM template's contents or external configuration.
AWS recommends installing `aws-sam-cli` using its native package installers (e.g., Homebrew, MSI, apt) to avoid these conflicts. If using pip, ensure `aws-sam-cli` and `aws-sam-translator` versions are compatible.
Ensure `CodeUri` references an S3 bucket path or use `InlineCode` for direct translation with the library. Local build artifacts (e.g., from `sam build`) are handled by the SAM CLI, not by the raw translator library.
Understand that `aws-sam-translator` generates CloudFormation. Deployment of this CloudFormation output requires further steps, typically via `aws-sam-cli deploy` or `aws cloudformation deploy`.
Always install `aws-sam-translator` with its specified `pydantic` version ranges or ensure your environment satisfies its dependency constraints. Refer to `requirements.txt` in the GitHub repository or PyPI metadata for the exact compatible `pydantic` versions.
Install the `PyYAML` package using pip: `pip install PyYAML`. Ensure this is done in the correct Python environment or virtual environment where your script or the library is being executed.
Ensure `PyYAML` is installed in the Python environment. Add `PyYAML` to your project's `requirements.txt` file (e.g., `PyYAML==6.0.1`) and install it using `pip install -r requirements.txt` or `pip install pyyaml`.
Ensure that the versions of aws-sam-cli and aws-sam-translator are compatible. You can do this by installing the aws-sam-cli using the native package installer, which manages dependencies automatically. Alternatively, if using pip, install the AWS SAM CLI into a virtual environment to avoid dependency conflicts. For more information, see the AWS SAM CLI troubleshooting guide.
Provide the --stack-name option when running the 'sam remote invoke' command. For example: 'sam remote invoke --stack-name sam-app'. For more details, refer to the AWS SAM CLI troubleshooting guide.
Set up AWS credentials to enable the AWS SAM CLI to make AWS service calls. For instructions, see the AWS SAM CLI troubleshooting guide.
Enable long paths in Windows 10, version 1607, and later to resolve this issue. For guidance, see the AWS SAM CLI troubleshooting guide.
Install Docker for your development host to enable local testing of AWS SAM applications. For more information, see the AWS SAM CLI troubleshooting guide.