sst 3.4.24 → 3.4.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ import { AwsOptions } from "./client.js";
2
+ /**
3
+ * The `task` client SDK is available through the following.
4
+ *
5
+ * @example
6
+ * ```js title="src/app.ts"
7
+ * import { task } from "sst/aws/task";
8
+ * ```
9
+ */
10
+ export declare namespace task {
11
+ /**
12
+ * The link data for the task.
13
+ *
14
+ * @example
15
+ * For example, let's say you have a task.
16
+ *
17
+ * ```js title="sst.config.ts"
18
+ * cluster.addTask("MyTask");
19
+ * ```
20
+ *
21
+ * `Resource.MyTask` will have all the link data.
22
+ *
23
+ * ```js title="src/app.ts"
24
+ * import { Resource } from "sst";
25
+ *
26
+ * console.log(Resource.MyTask);
27
+ * ```
28
+ */
29
+ interface Resource {
30
+ /**
31
+ * The ARN of the cluster.
32
+ */
33
+ cluster: string;
34
+ /**
35
+ * The ARN of the task definition.
36
+ */
37
+ taskDefinition: string;
38
+ /**
39
+ * The subnets to use for the task.
40
+ */
41
+ subnets: string[];
42
+ /**
43
+ * The security groups to use for the task.
44
+ */
45
+ securityGroups: string[];
46
+ /**
47
+ * Whether to assign a public IP address to the task.
48
+ */
49
+ assignPublicIp: boolean;
50
+ /**
51
+ * The names of the containers in the task.
52
+ */
53
+ containers: string[];
54
+ }
55
+ interface Options {
56
+ /**
57
+ * Configure the AWS client.
58
+ */
59
+ aws?: AwsOptions;
60
+ }
61
+ /**
62
+ * Gets the details of a task. Tasks stopped longer than 1 hour are not returned.
63
+ *
64
+ * @example
65
+ * For example, let's say you have started task.
66
+ *
67
+ * ```js title="src/app.ts"
68
+ * import { Resource } from "sst";
69
+ * import { task } from "sst/aws/task";
70
+ *
71
+ * const runRet = await task.run(Resource.MyTask);
72
+ * const taskArn = runRet.tasks[0].taskArn;
73
+ * ```
74
+ *
75
+ * You can get the details of the task with the following.
76
+ *
77
+ * ```js title="src/app.ts"
78
+ * const describeRet = await task.describe(Resource.MyTask, taskArn);
79
+ * ```
80
+ */
81
+ function describe(resource: Resource, task: string, options?: Options): Promise<any>;
82
+ /**
83
+ * Runs a task.
84
+ *
85
+ * @example
86
+ *
87
+ * For example, let's say you have a task.
88
+ *
89
+ * ```js title="sst.config.ts"
90
+ * cluster.addTask("MyTask");
91
+ * ```
92
+ *
93
+ * You can run it in your application with the following.
94
+ *
95
+ * ```js title="src/app.ts"
96
+ * import { Resource } from "sst";
97
+ * import { task } from "sst/aws/task";
98
+ *
99
+ * const runRet = await task.run(Resource.MyTask);
100
+ * const taskArn = runRet.tasks[0].taskArn;
101
+ * ```
102
+ *
103
+ * `taskArn` is the ARN of the task. You can pass it to the `describe` function to get
104
+ * the status of the task; or to the `stop` function to stop the task.
105
+ *
106
+ * You can also pass in environment variables to the task.
107
+ *
108
+ * ```js title="src/app.ts"
109
+ * await task.run(Resource.MyTask, {
110
+ * MY_ENV_VAR: "my-value",
111
+ * });
112
+ * ```
113
+ */
114
+ function run(resource: Resource, environment?: Record<string, string>, options?: {
115
+ aws?: AwsOptions;
116
+ }): Promise<any>;
117
+ /**
118
+ * Stops a task.
119
+ *
120
+ * @example
121
+ *
122
+ * For example, let's say you have started a task.
123
+ *
124
+ * ```js title="src/app.ts"
125
+ * import { Resource } from "sst";
126
+ * import { task } from "sst/aws/task";
127
+ *
128
+ * const runRet = await task.run(Resource.MyTask);
129
+ * const taskArn = runRet.tasks[0].taskArn;
130
+ * ```
131
+ *
132
+ * You can stop the task with the following.
133
+ *
134
+ * ```js title="src/app.ts"
135
+ * const stopRet = await task.stop(Resource.MyTask, taskArn);
136
+ *
137
+ * // check if the task is stopped
138
+ * console.log(stopRet.task?.lastStatus);
139
+ * ```
140
+ */
141
+ function stop(resource: Resource, task: string, options?: Options): Promise<any>;
142
+ class DescribeError extends Error {
143
+ readonly response: Response;
144
+ constructor(response: Response);
145
+ }
146
+ class RunError extends Error {
147
+ readonly response: Response;
148
+ constructor(response: Response);
149
+ }
150
+ class StopError extends Error {
151
+ readonly response: Response;
152
+ constructor(response: Response);
153
+ }
154
+ }
@@ -0,0 +1,197 @@
1
+ import { client } from "./client.js";
2
+ /**
3
+ * The `task` client SDK is available through the following.
4
+ *
5
+ * @example
6
+ * ```js title="src/app.ts"
7
+ * import { task } from "sst/aws/task";
8
+ * ```
9
+ */
10
+ export var task;
11
+ (function (task_1) {
12
+ function url(region, options) {
13
+ if (options?.region)
14
+ region = options.region;
15
+ return `https://ecs.${region}.amazonaws.com/`;
16
+ }
17
+ /**
18
+ * Gets the details of a task. Tasks stopped longer than 1 hour are not returned.
19
+ *
20
+ * @example
21
+ * For example, let's say you have started task.
22
+ *
23
+ * ```js title="src/app.ts"
24
+ * import { Resource } from "sst";
25
+ * import { task } from "sst/aws/task";
26
+ *
27
+ * const runRet = await task.run(Resource.MyTask);
28
+ * const taskArn = runRet.tasks[0].taskArn;
29
+ * ```
30
+ *
31
+ * You can get the details of the task with the following.
32
+ *
33
+ * ```js title="src/app.ts"
34
+ * const describeRet = await task.describe(Resource.MyTask, taskArn);
35
+ * ```
36
+ */
37
+ async function describe(resource, task, options) {
38
+ const c = await client();
39
+ const u = url(c.region, options?.aws);
40
+ const res = await c.fetch(u, {
41
+ method: "POST",
42
+ aws: options?.aws,
43
+ headers: {
44
+ "X-Amz-Target": "AmazonEC2ContainerServiceV20141113.DescribeTasks",
45
+ "Content-Type": "application/x-amz-json-1.1",
46
+ },
47
+ body: JSON.stringify({
48
+ cluster: resource.cluster,
49
+ tasks: [task],
50
+ }),
51
+ });
52
+ if (!res.ok)
53
+ throw new DescribeError(res);
54
+ return res.json();
55
+ }
56
+ task_1.describe = describe;
57
+ /**
58
+ * Runs a task.
59
+ *
60
+ * @example
61
+ *
62
+ * For example, let's say you have a task.
63
+ *
64
+ * ```js title="sst.config.ts"
65
+ * cluster.addTask("MyTask");
66
+ * ```
67
+ *
68
+ * You can run it in your application with the following.
69
+ *
70
+ * ```js title="src/app.ts"
71
+ * import { Resource } from "sst";
72
+ * import { task } from "sst/aws/task";
73
+ *
74
+ * const runRet = await task.run(Resource.MyTask);
75
+ * const taskArn = runRet.tasks[0].taskArn;
76
+ * ```
77
+ *
78
+ * `taskArn` is the ARN of the task. You can pass it to the `describe` function to get
79
+ * the status of the task; or to the `stop` function to stop the task.
80
+ *
81
+ * You can also pass in environment variables to the task.
82
+ *
83
+ * ```js title="src/app.ts"
84
+ * await task.run(Resource.MyTask, {
85
+ * MY_ENV_VAR: "my-value",
86
+ * });
87
+ * ```
88
+ */
89
+ async function run(resource, environment, options) {
90
+ const c = await client();
91
+ const u = url(c.region, options?.aws);
92
+ const res = await c.fetch(u, {
93
+ method: "POST",
94
+ aws: options?.aws,
95
+ headers: {
96
+ "X-Amz-Target": "AmazonEC2ContainerServiceV20141113.RunTask",
97
+ "Content-Type": "application/x-amz-json-1.1",
98
+ },
99
+ body: JSON.stringify({
100
+ cluster: resource.cluster,
101
+ launchType: "FARGATE",
102
+ taskDefinition: resource.taskDefinition,
103
+ networkConfiguration: {
104
+ awsvpcConfiguration: {
105
+ subnets: resource.subnets,
106
+ securityGroups: resource.securityGroups,
107
+ assignPublicIp: resource.assignPublicIp ? "ENABLED" : "DISABLED",
108
+ },
109
+ },
110
+ overrides: {
111
+ containerOverrides: resource.containers.map((name) => ({
112
+ name,
113
+ environment: Object.entries(environment ?? {}).map(([key, value]) => ({
114
+ name: key,
115
+ value,
116
+ })),
117
+ })),
118
+ },
119
+ }),
120
+ });
121
+ if (!res.ok)
122
+ throw new RunError(res);
123
+ return res.json();
124
+ }
125
+ task_1.run = run;
126
+ /**
127
+ * Stops a task.
128
+ *
129
+ * @example
130
+ *
131
+ * For example, let's say you have started a task.
132
+ *
133
+ * ```js title="src/app.ts"
134
+ * import { Resource } from "sst";
135
+ * import { task } from "sst/aws/task";
136
+ *
137
+ * const runRet = await task.run(Resource.MyTask);
138
+ * const taskArn = runRet.tasks[0].taskArn;
139
+ * ```
140
+ *
141
+ * You can stop the task with the following.
142
+ *
143
+ * ```js title="src/app.ts"
144
+ * const stopRet = await task.stop(Resource.MyTask, taskArn);
145
+ *
146
+ * // check if the task is stopped
147
+ * console.log(stopRet.task?.lastStatus);
148
+ * ```
149
+ */
150
+ async function stop(resource, task, options) {
151
+ const c = await client();
152
+ const u = url(c.region, options?.aws);
153
+ const res = await c.fetch(u, {
154
+ method: "POST",
155
+ aws: options?.aws,
156
+ headers: {
157
+ "X-Amz-Target": "AmazonEC2ContainerServiceV20141113.StopTask",
158
+ "Content-Type": "application/x-amz-json-1.1",
159
+ },
160
+ body: JSON.stringify({
161
+ cluster: resource.cluster,
162
+ task,
163
+ }),
164
+ });
165
+ if (!res.ok)
166
+ throw new StopError(res);
167
+ return res.json();
168
+ }
169
+ task_1.stop = stop;
170
+ class DescribeError extends Error {
171
+ response;
172
+ constructor(response) {
173
+ super("Failed to describe task");
174
+ this.response = response;
175
+ console.log(response);
176
+ }
177
+ }
178
+ task_1.DescribeError = DescribeError;
179
+ class RunError extends Error {
180
+ response;
181
+ constructor(response) {
182
+ super("Failed to run task");
183
+ this.response = response;
184
+ console.log(response);
185
+ }
186
+ }
187
+ task_1.RunError = RunError;
188
+ class StopError extends Error {
189
+ response;
190
+ constructor(response) {
191
+ super("Failed to stop task");
192
+ this.response = response;
193
+ console.log(response);
194
+ }
195
+ }
196
+ task_1.StopError = StopError;
197
+ })(task || (task = {}));