Shop Stack
This page builds the shop, the application the rest of these pages use as their example. By the end it exists in your own AWS account: a network to run in, a bucket where the checkout service keeps the receipts customers upload, and checkout itself, a function with permission to read and write that bucket and nothing else.
None of the ten boxes mentions AWS. You build it in two passes: first the region and the bucket, then checkout on top of them, which is where the dotted line becomes a permission. The second region is the place checkout's function lives, one with no network, because a function needs none.
A VPC, an internet gateway, an empty S3 bucket, an IAM role and a function nobody calls are free to create. The checkout image sits in ECR, which bills about $0.10 per GB-month. The teardown at the end removes all of it.
The output on this page comes from real runs of the shop. Provider-assigned ids are shown as
<prefix>-0123456789abcdef0, and the account is 123456789012.
The definition file
Give the shop a project of its own:
npx @quadnix/octo-build create-app -n shop
cd shop
Then replace octo.yaml with this:
version: 1
env:
- key: AWS_ACCOUNT_ID
kind: string
value: "123456789012" # your AWS account number
- key: RECEIPTS_BUCKET_NAME
kind: string
value: shop-receipts # a name of your own
terraform:
requiredVersion: "1.6.0"
requiredProviders:
aws:
source: hashicorp/aws
providers:
- providerType: aws
accountId: "${env.AWS_ACCOUNT_ID}"
regionId: eu-west-1
spec:
profile: default # your profile in ~/.aws/credentials
settings:
listeners:
- type: LoggingEventListener
stateProvider:
type: LocalStateProvider
statePath: .octo
imports:
- className: SimpleAppModule
importPath: "@quadnix/octo-aws-cdk/modules/app/simple-app"
- className: AwsIniAccountModule
importPath: "@quadnix/octo-aws-cdk/modules/account/aws-ini-account"
- className: AwsSingleAzRegionModule
importPath: "@quadnix/octo-aws-cdk/modules/region/aws-single-az-region"
- className: AwsS3StorageServiceModule
importPath: "@quadnix/octo-aws-cdk/modules/service/aws-s3-storage-service"
modules:
- moduleId: app-module
moduleClass: SimpleAppModule
moduleInputs:
name: shop
- moduleId: account-module
moduleClass: AwsIniAccountModule
moduleInputs:
accountId: "${env.AWS_ACCOUNT_ID}"
app: "${{app-module.model.app}}"
- moduleId: region-module
moduleClass: AwsSingleAzRegionModule
moduleInputs:
account: "${{account-module.model.account}}"
name: eu-west-1
regionId: aws-eu-west-1a
vpcCidrBlock: 10.0.0.0/16
- moduleId: receipts-module
moduleClass: AwsS3StorageServiceModule
moduleInputs:
region: "${{region-module.model.region}}"
bucketName: "${env.RECEIPTS_BUCKET_NAME}"
accessPrefixes:
- uploads
The file has five parts. env holds the values you change, terraform is the provider setup that
would otherwise open every .tf file, and settings says where Octo keeps its state. imports
names the module classes the file uses, and modules is the infrastructure itself. The Definition
File covers each part.
The account module is handed the app the app module built, through ${{app-module.model.app}}, and
not the string "shop". That is what makes the list a graph: the region knows its account, and
the bucket knows its region, without anybody repeating an account number or a region name.
Generate and validate
npm run octo:generate
npm run octo:validate
generate writes two folders of Terraform into .octo-tf, one for the region and one for the
bucket. The app and the account create nothing in AWS, so they have no folder. The Terraform inside
is ordinary, and it is committed with the change so a reviewer sees what the YAML turned into:
resource "aws_s3_bucket" "bucket-shop-receipts-914372" {
provider = aws._123456789012-eu-west-1
bucket = "shop-receipts"
}
resource "aws_s3_bucket_public_access_block" "bucket-shop-receipts-914372-public-access" {
provider = aws._123456789012-eu-west-1
block_public_acls = true
block_public_policy = true
bucket = aws_s3_bucket.bucket-shop-receipts-914372.id
ignore_public_acls = true
restrict_public_buckets = true
depends_on = [aws_s3_bucket.bucket-shop-receipts-914372]
}
The bucket is not the only thing the module wrote: the receipts module also closes the bucket to the public, and the six-character suffix on each name is a hash of where in the graph the bucket sits, which keeps two buckets of one name apart.
validate plans both folders and reports the plans against what you asked for:
shop — octo validate — changes (approximate)
2026-11-26 16:34:13 UTC · 4ms octo · 5.7s terraform
You added region=eu-west-1 (+1 other change). That creates 4 new things.
- 0 destroy ± 0 replace + 4 create ~ 0 update
Your intent changed, so each folder was planned on its own against its dependencies' last
applied outputs. A cross-folder consequence of this change is invisible until apply. This
report can both understate what apply will do and overstate drift.
WHAT WILL CHANGE
+ added region=eu-west-1 [region=eu-west-1,account=123456789012,app=shop | region-module | +2]
+ vpc-eu-west-1-f38b9d
+ aws_vpc.vpc-eu-west-1-f38b9d
+ igw-eu-west-1-f38b9d
+ aws_internet_gateway.igw-eu-west-1-f38b9d
+ added service=shop-receipts-s3-storage [service=shop-receipts-s3-storage,region=eu-west-1,account=123456789012,app=shop | receipts-module | +2]
+ bucket-shop-receipts-914372
+ aws_s3_bucket_public_access_block.bucket-shop-receipts-914372-public-access
+ aws_s3_bucket.bucket-shop-receipts-914372
Each card starts at something you asked for, a region or a receipts service, and goes down to the Terraform resources it takes. The report calls itself approximate because the infrastructure does not exist yet; Reading a Validate Report explains what that changes.
Apply and commit
npm run octo:lock
npm run octo:apply
npm run octo:commit
The apply prints Terraform's progress as it goes and takes a few seconds here. The commit then records the values only AWS could know:
WHAT OCTO RECORDED — values that moved
@octo/vpc=vpc-eu-west-1-f38b9d VpcArn: - → arn:aws:ec2:eu-west-1:123456789012:vpc/vpc-0123456789abcdef0
@octo/vpc=vpc-eu-west-1-f38b9d VpcId: - → vpc-0123456789abcdef0
@octo/internet-gateway=igw-eu-west-1-f38b9d InternetGatewayArn: - → arn:aws:ec2:eu-west-1:123456789012:internet-gateway/igw-0123456789abcdef0
@octo/internet-gateway=igw-eu-west-1-f38b9d InternetGatewayId: - → igw-0123456789abcdef0
@octo/s3-storage=bucket-shop-receipts-914372 Arn: - → arn:aws:s3:::shop-receipts
@octo/s3-storage=bucket-shop-receipts-914372 awsRegionId: - → eu-west-1
@octo/s3-storage=bucket-shop-receipts-914372 Bucket: - → shop-receipts
@octo/s3-storage=bucket-shop-receipts-914372 RegionalDomainName: - → shop-receipts.s3.eu-west-1.amazonaws.com
From now on, anything that needs to point at the bucket or the VPC reads these values from Octo's record rather than from a string somebody typed.
Give checkout access
Checkout is a function that runs from a container image, and it needs to read and write the
uploads folder of the receipts bucket. Octo splits that into the pieces that can change on their
own. The server is who checkout is and what it may reach. The deployment is one version of its code.
The execution is where that version runs, and it is the only one of the three that creates anything
in AWS. Add the classes to imports:
- className: AwsServerlessRegionModule
importPath: "@quadnix/octo-aws-cdk/modules/region/aws-serverless-region"
- className: AwsServerlessEnvironmentModule
importPath: "@quadnix/octo-aws-cdk/modules/environment/aws-serverless-environment"
- className: AwsServerlessSubnetModule
importPath: "@quadnix/octo-aws-cdk/modules/subnet/aws-serverless-subnet"
- className: AwsEcrImageModule
importPath: "@quadnix/octo-aws-cdk/modules/image/aws-ecr-image"
- className: AwsEcrImageTagModule
importPath: "@quadnix/octo-aws-cdk/modules/image/aws-ecr-image-tag"
- className: AwsServerModule
importPath: "@quadnix/octo-aws-cdk/modules/server/aws-server"
- className: AwsDeploymentModule
importPath: "@quadnix/octo-aws-cdk/modules/deployment/aws-deployment"
- className: AwsLambdaExecutionModule
importPath: "@quadnix/octo-aws-cdk/modules/execution/aws-lambda-execution"
and add checkout at the end of modules. A function needs no network, so it lives in a second
region that creates nothing, with the staging environment and the one subnet that region has. The
image is built from the checkout folder of your project, which holds checkout's Dockerfile;
Publishing an Image covers writing it.
- moduleId: functions-region-module
moduleClass: AwsServerlessRegionModule
moduleInputs:
account: "${{account-module.model.account}}"
name: eu-west-1-functions
regionId: aws-eu-west-1
- moduleId: image-module
moduleClass: AwsEcrImageModule
moduleInputs:
imageFamily: shop
imageName: checkout
regions:
- "${{functions-region-module.model.region}}"
- moduleId: image-tag-module
moduleClass: AwsEcrImageTagModule
moduleInputs:
architecture: arm64
dockerfileDirectory: checkout
dockerfileName: Dockerfile
image: "${{image-module.model.image}}"
imageTag: 0.0.1
- moduleId: staging-module
moduleClass: AwsServerlessEnvironmentModule
moduleInputs:
environmentName: staging
region: "${{functions-region-module.model.region}}"
- moduleId: subnet-module
moduleClass: AwsServerlessSubnetModule
moduleInputs:
region: "${{functions-region-module.model.region}}"
- moduleId: checkout-server-module
moduleClass: AwsServerModule
moduleInputs:
account: "${{account-module.model.account}}"
serverKey: checkout
s3:
- service: "${{receipts-module.model.service}}"
accessPrefixes:
- access: READ_WRITE
accessPrefix: uploads
- moduleId: checkout-deployment-module
moduleClass: AwsDeploymentModule
moduleInputs:
deploymentTag: v1
image: "${{image-module.model.image}}"
imageTag: 0.0.1
memory: 512
ports:
- containerPort: 8080
protocol: tcp
server: "${{checkout-server-module.model.server}}"
timeoutInSeconds: 30
- moduleId: checkout-execution-module
moduleClass: AwsLambdaExecutionModule
moduleInputs:
deployment: "${{checkout-deployment-module.model.deployment}}"
environment: "${{staging-module.model.environment}}"
executionId: shop-checkout
subnet: "${{subnet-module.model.subnet}}"
There is no policy document in there, and no ARN. The server is handed the receipts service itself,
and asks for READ_WRITE on one folder of it. Run generate and validate again:
You added @octo/aws-lambda-execution-overlay=aws-lambda-execution-overlay-5c2221a926e9 (+3 other changes). That creates 12 new things.
- 0 destroy ± 0 replace + 12 create ~ 0 update
WHAT WILL CHANGE
+ added @octo/aws-lambda-execution-overlay=aws-lambda-execution-overlay-5c2221a926e9 [@octo/aws-lambda-execution-overlay=aws-lambda-execution-overlay-5c2221a926e9 | checkout-execution-module | +8]
+ cloudwatch-log-group-shop-checkout-5cca84
+ aws_cloudwatch_log_group.cloudwatch-log-group-shop-checkout-5cca84
+ iam-role-ExecutionRole-shop-checkout-5cca84
+ aws_iam_policy.iam-role-ExecutionRole-shop-checkout-5cca84_ExecutionRole-shop-checkout-e1c99648347b
+ aws_iam_policy.iam-role-ExecutionRole-shop-checkout-5cca84_ExecutionRole-shop-checkout-logs
+ aws_iam_role_policy_attachment.iam-role-ExecutionRole-shop-checkout-5cca84_ExecutionRole-shop-checkout-e1c99648347b_attach
+ aws_iam_role_policy_attachment.iam-role-ExecutionRole-shop-checkout-5cca84_ExecutionRole-shop-checkout-logs_attach
+ aws_iam_role.iam-role-ExecutionRole-shop-checkout-5cca84
+ lambda-function-shop-checkout-5cca84
+ aws_lambda_function_url.lambda-function-shop-checkout-5cca84_url
+ aws_lambda_function.lambda-function-shop-checkout-5cca84
+ added image=shop/checkout [image=shop/checkout,account=123456789012,app=shop | image-module | +2]
+ ecr-eu-west-1-shop/checkout-f38b9d
+ aws_ecr_lifecycle_policy.ecr-eu-west-1-shop_checkout-f38b9d-lifecycle-policy
+ aws_ecr_repository.ecr-eu-west-1-shop_checkout-f38b9d
~ changed service=shop-receipts-s3-storage [service=shop-receipts-s3-storage,region=eu-west-1,account=123456789012,app=shop | receipts-module | +1]
~ bucket-shop-receipts-914372
+ aws_s3_bucket_policy.bucket-shop-receipts-914372-policy
+ added @octo/aws-ecr-image-tag-overlay=aws-ecr-image-tag-overlay-348f8211579f [@octo/aws-ecr-image-tag-overlay=aws-ecr-image-tag-overlay-348f8211579f | image-tag-module | +1]
+ ecr-image-tag-eu-west-1-shop/checkout-0-0-1-f38b9d
+ null_resource.ecr-image-tag-eu-west-1-shop_checkout-0-0-1-f38b9d
The server and the deployment are not in the report, because they create nothing. The execution
does: the headline names its overlay, the node that joins the function to the server, the
environment, the image and the grant, and its card holds the function, its URL, and the role the
function runs as. The role has two policies, one for writing its logs and one holding the S3 actions
READ_WRITE means, confined to uploads, as somebody worked them out once inside the execution
module.
AWS wants an S3 grant written on both sides, so the receipts folder gets a bucket policy naming that
role, which is the one line under the changed card. The bucket policy names a role that does not
exist yet, so the two folders have to be applied in order. Octo wrote that order into the generated
Terraform, so the role is created first without anybody saying so:
dependency "checkout-execution-module" {
config_path = "../checkout-execution-module"
mock_outputs = {
"iam-role-ExecutionRole-shop-checkout-5cca84-Arn" = "arn:aws:iam::000000000000:role/mock-role"
}
mock_outputs_allowed_terraform_commands = ["init", "plan", "show", "validate"]
mock_outputs_merge_strategy_with_state = "shallow"
}
The apply also builds the image with Docker and pushes it to ECR, so it takes longer than the first one.
npm run octo:lock
npm run octo:apply
npm run octo:commit
Tear it down
Comment out every module except the app and the account, and run the lifecycle again:
npm run octo:generate
npm run octo:lock
npm run octo:apply -- --auto-approve
npm run octo:commit
Without --auto-approve, the apply refuses and lists what it would remove, marking the bucket as
one that takes its data with it. Destroying
Infrastructure covers reading that list and approving
one destroy at a time.