Parameters & Outputs
Show the whole prompt
Read https://intentius.io/chant/getting-started/parameters-and-outputs/.
Add the CloudFormation parameters and stack outputs I describe to this project: an exported `Parameter` for each input, `Ref` or an import where a resource uses it, and `output()` for each value to expose.
Run `npx chant build -o template.json` and show me the template's `Parameters` and `Outputs` sections, then run `npx chant lint` and open a pull request.
Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes` or `chant release publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.Optional: hand this page to your coding agent
Read https://intentius.io/chant/getting-started/parameters-and-outputs/.Add the CloudFormation parameters and stack outputs I describe to this project: an exported `Parameter` for each input, `Ref` or an import where a resource uses it, and `output()` for each value to expose.Run `npx chant build -o template.json` and show me the template's `Parameters` and `Outputs` sections, then run `npx chant lint` and open a pull request.Never deploy to a real cloud account or shared environment (with `chant run`, `chant components` or a platform's own CLI), approve (a pull request review, `chant approve` or `chant run approve`), override a policy denial (`chant approve policy-override`), or merge; never cut or publish a release (`chant release cut --yes` or `chant release publish`), push or delete a `ci/*` tag (`chant ci tick` pushes them), or change the value of an existing flag; never touch `.chant/allowed_signers` or `chant/lifecycle`.Parameters let you customize a stack at deploy time. Outputs expose values from the stack for use by other stacks or scripts.
This page is about Parameter, a deploy-time input that resolves when the stack applies. To vary the build itself (which environment, which tier, which resources are even produced), see Build-Time Parameters.
Full example
Section titled “Full example”import { ServerSideEncryptionByDefault, ServerSideEncryptionRule, BucketEncryption, PublicAccessBlockConfiguration, VersioningConfiguration,} from "@intentius/chant-lexicon-aws";
export const encryptionDefault = new ServerSideEncryptionByDefault({ SSEAlgorithm: "AES256",});
export const encryptionRule = new ServerSideEncryptionRule({ ServerSideEncryptionByDefault: encryptionDefault,});
export const bucketEncryption = new BucketEncryption({ ServerSideEncryptionConfiguration: [encryptionRule],});
export const publicAccessBlock = new PublicAccessBlockConfiguration({ BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true,});
export const versioningEnabled = new VersioningConfiguration({ Status: "Enabled",});
export const lambdaTrustPolicy = { Version: "2012-10-17", Statement: [ { Effect: "Allow", Principal: { Service: "lambda.amazonaws.com" }, Action: "sts:AssumeRole", }, ],};
export const lambdaBasicExecutionArn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole";import { Parameter } from "@intentius/chant-lexicon-aws";
export const environment = new Parameter("String", { description: "Deployment environment", defaultValue: "dev",});Parameters
Section titled “Parameters”Export a Parameter to add it to the template’s Parameters section:
import { Parameter } from "@intentius/chant-lexicon-aws";
export const environment = new Parameter("String", { description: "Deployment environment", defaultValue: "dev",});The first argument is the CloudFormation parameter type ("String", "Number", "List<Number>", "CommaDelimitedList", or an AWS SSM type). The second argument supports:
description— human-readable descriptiondefaultValue— value used when none is provided at deploy time
The exported variable name becomes the logical parameter name (PascalCased). name becomes Name in the template.
Referencing parameters
Section titled “Referencing parameters”Use Ref to reference a parameter’s value inside resource properties:
import { Bucket, Sub, Ref } from "@intentius/chant-lexicon-aws";
export const paramRefBucket = new Bucket({ BucketName: Sub`${Ref("Environment")}-data`, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true, },});Or import it directly when the parameter is in another file:
import { Bucket, Sub, Ref } from "@intentius/chant-lexicon-aws";import { environment } from "./parameter-declaration";
export const crossRefBucket = new Bucket({ BucketName: Sub`${Ref(environment)}-data`, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true, },});Outputs
Section titled “Outputs”Use output() to create explicit stack outputs. An output wraps an AttrRef (a resource attribute reference) with a name:
import { Bucket, Sub, AWS, output } from "@intentius/chant-lexicon-aws";
export const dataBucket = new Bucket({ BucketName: Sub`${AWS.StackName}-data`, PublicAccessBlockConfiguration: { BlockPublicAcls: true, BlockPublicPolicy: true, IgnorePublicAcls: true, RestrictPublicBuckets: true, },});
export const dataBucketArn = output(dataBucket.Arn, "DataBucketArn");This produces:
"Outputs": { "DataBucketArn": { "Value": { "Fn::GetAtt": ["DataBucket", "Arn"] } }}Next steps
Section titled “Next steps”- AWS CloudFormation Concepts — pseudo-parameters, intrinsics, conditions, and more
- Nested Stacks — cross-stack references with
stackOutput()