0

Assign or update a VPC endpoint restriction

by
Published Apr 8, 2025

Configures the specified VPC endpoint as restriction for the project, or updates the existing restriction. When a VPC endpoint is assigned as a restriction, only connections from this specific VPC are accepted. Note that a VPC endpoint can only used as a restriction on a project after it has been assigned to the parent organization. This endpoint is under active development and its semantics may change in the future.

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Assign or update a VPC endpoint restriction
7
 * Configures the specified VPC endpoint as restriction for the project,
8
or updates the existing restriction. When a VPC endpoint is assigned
9
as a restriction, only connections from this specific VPC are accepted.
10
Note that a VPC endpoint can only used as a restriction on a project
11
after it has been assigned to the parent organization.
12
This endpoint is under active development and its semantics may change in the future.
13

14
 */
15
export async function main(
16
	auth: Neondb,
17
	project_id: string,
18
	vpc_endpoint_id: string,
19
	body: { label: string }
20
) {
21
	const url = new URL(
22
		`https://console.neon.tech/api/v2/projects/${project_id}/vpc-endpoints/${vpc_endpoint_id}`
23
	)
24

25
	const response = await fetch(url, {
26
		method: 'POST',
27
		headers: {
28
			'Content-Type': 'application/json',
29
			Authorization: 'Bearer ' + auth.apiKey
30
		},
31
		body: JSON.stringify(body)
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39