Print from AWS to a printer behind a firewall
A server on AWS does not need a path to the printer's private IP. The office agent connects outbound and your server posts a job.
For Backend developers printing from a VPC
This page in another language: 中文
Overview
From a VPC, the printer's 192.168.x.x address does not exist. A VPN or a port forward would create a path, and a port forward would publish the printer. The agent removes that requirement: it runs in the office and opens an outbound WebSocket.
The AWS service needs outbound HTTPS to the API and the API key. It does not need a security-group rule toward the office. The office firewall needs to allow the agent out. It does not need an inbound rule for PrintBase.
Use the job status to see AGENT_OFFLINE when that office PC is asleep. That is a clearer signal than a VPN tunnel that is up while the printer is not.
Integration steps
- 01
Install the agent in the office
Not on the EC2 instance, unless the printer is somehow on that instance.
- 02
Allow the agent outbound
To api.printbase.cloud or the China host if you selected it.
- 03
POST from the VPC
No private IP in the JSON. printer_code only. Use POST /v1/print-jobs with Authorization: Bearer and the printer_code from GET /v1/printers.
- 04
Do not port-forward 9100
That exposes a printer protocol. It is unnecessary here. Use POST /v1/print-jobs with Authorization: Bearer and the printer_code from GET /v1/printers.
Node.js
// Job from a cloud server, no printer IP
const res = await fetch('https://api.printbase.cloud/v1/print-jobs', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PRINTBASE_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
},
body: JSON.stringify({
printer_code: Number(process.env.PRINTER_CODE),
content_type: 'pdf',
content: pdf.toString('base64'),
copies: 1,
}),
});
if (!res.ok) throw new Error(`PrintBase ${res.status}: ${await res.text()}`);
const job = await res.json();
// { id: "job_abc", status: "queued" }
Details for this setup
content_url and private buckets
The agent downloads content_url. A URL that only resolves inside the VPC will fail with DOWNLOAD_FAILED. Use base64 or a presigned URL the agent can reach.
Same for Azure or a local server
The caller only needs HTTPS. The network you deploy on does not change the JSON.
Questions
Should the EC2 instance join the office VPN?
Not for printing. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Which security group port?
Outbound 443 to the API. No inbound from the printer. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
Can I pass the printer IP as printer_code?
No. printer_code is the integer from GET /v1/printers. The call is still POST /v1/print-jobs with a Bearer API key, and HTTP 201 means queued rather than printed.
The job stays queued.
The agent is not connected, or the printer is offline. Read the reason.
Free plan: 100 jobs a month on one computer, no card.