nomoss 0.0.3 → 0.0.5
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.
- package/CHANGELOG.md +34 -0
- package/README.md +5 -15
- package/ROADMAP.md +2 -0
- package/docs/README.md +1 -1
- package/docs/application/aws-resource-coverage.md +26 -0
- package/docs/application/aws-resource-lifecycle-management.md +13 -23
- package/docs/application/cli-workflow.md +1 -1
- package/docs/application/engine-design.md +2 -2
- package/docs/application/generation-architecture.md +10 -45
- package/docs/application/resource-command-policy-stage.md +2 -2
- package/docs/application/resource-graph.md +1 -1
- package/docs/application/resource-lifecycle-tracker.md +1 -9
- package/docs/application/resource-mapping.md +4 -9
- package/docs/application/resource-operations.md +4 -2
- package/docs/application/tracing.md +2 -6
- package/docs/development/code-documentation.md +2 -0
- package/docs/development/effect-native-development.md +44 -0
- package/docs/development/linting.md +1 -1
- package/docs/development/review-code.md +22 -6
- package/docs/development/review-remediation-spec.md +28 -37
- package/docs/development/spec-writing.md +1 -1
- package/docs/development/testing.md +23 -9
- package/docs/operations/observability-sop.md +11 -17
- package/docs/operations/releasing.md +3 -1
- package/examples/README.md +3 -26
- package/examples/commands.ts +2 -36
- package/examples/queue/application.ts +8 -2
- package/examples/state-machine/application.ts +3 -1
- package/package.json +40 -46
- package/providers/aws/README.md +21 -0
- package/providers/aws/awsEnvironment.ts +114 -0
- package/providers/aws/generated/managementRegistry.ts +136 -0
- package/{src/providers/aws/resources/generated/native/apigatewayv2/api/index.ts → providers/aws/generated/resources/apigatewayv2/api.ts} +13 -50
- package/{src/providers/aws/resources/generated/native/apigatewayv2/integration/index.ts → providers/aws/generated/resources/apigatewayv2/integration.ts} +13 -37
- package/{src/providers/aws/resources/generated/native/apigatewayv2/route/index.ts → providers/aws/generated/resources/apigatewayv2/route.ts} +23 -40
- package/{src/providers/aws/resources/generated/native/apigatewayv2/stage/index.ts → providers/aws/generated/resources/apigatewayv2/stage.ts} +13 -38
- package/providers/aws/generated/resources/iam/accesskey.ts +184 -0
- package/{src/providers/aws/resources/generated/native/iam/group/index.ts → providers/aws/generated/resources/iam/group.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/grouppolicy/index.ts → providers/aws/generated/resources/iam/grouppolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/instanceprofile/index.ts → providers/aws/generated/resources/iam/instanceprofile.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/iam/managedpolicy/index.ts → providers/aws/generated/resources/iam/managedpolicy.ts} +13 -95
- package/providers/aws/generated/resources/iam/oidcprovider.ts +314 -0
- package/{src/providers/aws/resources/generated/native/iam/policy/index.ts → providers/aws/generated/resources/iam/policy.ts} +13 -28
- package/{src/providers/aws/resources/generated/native/iam/role/index.ts → providers/aws/generated/resources/iam/role.ts} +13 -47
- package/{src/providers/aws/resources/generated/native/iam/rolepolicy/index.ts → providers/aws/generated/resources/iam/rolepolicy.ts} +29 -59
- package/providers/aws/generated/resources/iam/samlprovider.ts +463 -0
- package/providers/aws/generated/resources/iam/servercertificate.ts +465 -0
- package/providers/aws/generated/resources/iam/servicelinkedrole.ts +187 -0
- package/{src/providers/aws/resources/generated/native/iam/user/index.ts → providers/aws/generated/resources/iam/user.ts} +13 -38
- package/{src/providers/aws/resources/generated/native/iam/userpolicy/index.ts → providers/aws/generated/resources/iam/userpolicy.ts} +29 -59
- package/{src/providers/aws/resources/generated/native/iam/usertogroupaddition/index.ts → providers/aws/generated/resources/iam/usertogroupaddition.ts} +13 -27
- package/providers/aws/generated/resources/iam/virtualmfadevice.ts +298 -0
- package/{src/providers/aws/resources/generated/native/kms/key/index.ts → providers/aws/generated/resources/kms/key.ts} +13 -41
- package/{src/providers/aws/resources/generated/native/lambda/function/index.ts → providers/aws/generated/resources/lambda/function.ts} +13 -63
- package/{src/providers/aws/resources/generated/native/lambda/permission/index.ts → providers/aws/generated/resources/lambda/permission.ts} +13 -55
- package/{src/providers/aws/resources/generated/native/s3/bucket/index.ts → providers/aws/generated/resources/s3/bucket.ts} +14 -104
- package/{src/providers/aws/resources/generated/native/sns/topic/index.ts → providers/aws/generated/resources/sns/topic.ts} +14 -29
- package/{src/providers/aws/resources/generated/native/sqs/queue/index.ts → providers/aws/generated/resources/sqs/queue.ts} +14 -38
- package/{src/providers/aws/resources/generated/native/stepfunctions/statemachine/index.ts → providers/aws/generated/resources/stepfunctions/statemachine.ts} +15 -58
- package/providers/aws/management/mappings/iam/group.ts +63 -0
- package/providers/aws/management/mappings/iam/iamIdentity.ts +41 -0
- package/providers/aws/management/mappings/iam/iamLifecycleSettings.ts +8 -0
- package/providers/aws/management/mappings/iam/inlinePolicies.ts +159 -0
- package/providers/aws/management/mappings/iam/instanceProfile.ts +77 -0
- package/providers/aws/management/mappings/iam/oidcProvider.ts +94 -0
- package/providers/aws/management/mappings/iam/role.ts +74 -0
- package/providers/aws/management/mappings/iam/samlProvider.ts +98 -0
- package/providers/aws/management/mappings/iam/serverCertificate.ts +72 -0
- package/providers/aws/management/mappings/iam/user.ts +61 -0
- package/providers/aws/management/mappings/iam/userToGroupAddition.ts +75 -0
- package/providers/aws/management/operations/iam/accessKey.ts +206 -0
- package/providers/aws/management/operations/iam/managedPolicy.ts +491 -0
- package/providers/aws/management/operations/iam/policy.ts +476 -0
- package/providers/aws/management/operations/iam/serviceLinkedRole.ts +172 -0
- package/providers/aws/management/operations/iam/virtualMfaDevice.ts +253 -0
- package/providers/aws/management/resourceAssociationConfiguration.ts +112 -0
- package/providers/aws/management/resourceAssociationRegistration.ts +349 -0
- package/providers/aws/management/resourceAssociations.ts +168 -0
- package/{src/providers → providers}/aws/management/resourceConfiguration.ts +24 -26
- package/providers/aws/management/resourceLifecycleRegistration.ts +540 -0
- package/providers/aws/management/resourceManagementModule.ts +31 -0
- package/providers/aws/management/resourceManagementRegistry.ts +62 -0
- package/providers/aws/management/resourceMapping.ts +84 -0
- package/providers/aws/management/resourceOperation.ts +134 -0
- package/providers/aws/management/resourceTagOperations.ts +108 -0
- package/providers/aws/management/resourceTiming.ts +4 -0
- package/providers/aws/runtime.ts +52 -0
- package/src/core/resource/resourceCommandPolicy.ts +20 -0
- package/src/core/resource/resourceLifecycle.ts +644 -0
- package/src/core/resource/resourceStabilization.ts +120 -0
- package/src/core/resource/resourceVersions.ts +102 -0
- package/src/core/stack/planner.ts +9 -0
- package/src/core/stack/resourceStackLifecycle.ts +36 -3
- package/src/core/state/resourceState.ts +6 -4
- package/src/core/state/stateStore.ts +57 -10
- package/src/providers/file/resourcePolicy.ts +13 -12
- package/src/providers/providerRuntimeLayer.ts +5 -2
- package/src/providers/resourceCommandPolicyLayer.ts +117 -37
- package/src/providers/stripe/management/resourcePolicy.ts +22 -11
- package/examples/http-echo/application.ts +0 -87
- package/src/providers/aws/client/awsClient.ts +0 -418
- package/src/providers/aws/client/awsClientConfig.ts +0 -133
- package/src/providers/aws/client/awsClientModel.ts +0 -119
- package/src/providers/aws/client/awsHttpOperation.ts +0 -153
- package/src/providers/aws/client/awsQueryOperation.ts +0 -149
- package/src/providers/aws/client/awsRequestSigner.ts +0 -115
- package/src/providers/aws/client/awsResponseDecoder.ts +0 -135
- package/src/providers/aws/client/awsRetryPolicy.ts +0 -62
- package/src/providers/aws/client/generated/apiGatewayV2.ts +0 -3025
- package/src/providers/aws/client/generated/cloudControl.ts +0 -5746
- package/src/providers/aws/client/generated/iam.ts +0 -10892
- package/src/providers/aws/client/generated/lambda.ts +0 -5403
- package/src/providers/aws/client/generated/sqs.ts +0 -3769
- package/src/providers/aws/client/generated/stepFunctions.ts +0 -1726
- package/src/providers/aws/client/openapi/cloudControl/CancelResourceRequest.json +0 -579
- package/src/providers/aws/client/openapi/cloudControl/CreateResource.json +0 -1019
- package/src/providers/aws/client/openapi/cloudControl/DeleteResource.json +0 -1018
- package/src/providers/aws/client/openapi/cloudControl/GetResource.json +0 -883
- package/src/providers/aws/client/openapi/cloudControl/GetResourceRequestStatus.json +0 -655
- package/src/providers/aws/client/openapi/cloudControl/ListResourceRequests.json +0 -566
- package/src/providers/aws/client/openapi/cloudControl/ListResources.json +0 -913
- package/src/providers/aws/client/openapi/cloudControl/UpdateResource.json +0 -1027
- package/src/providers/aws/cloudControl/client.ts +0 -69
- package/src/providers/aws/cloudControl/requestTracker.ts +0 -138
- package/src/providers/aws/cloudControl/resourceCommandPolicyLayer.ts +0 -63
- package/src/providers/aws/cloudControl/resourceLifecycle.ts +0 -479
- package/src/providers/aws/cloudControl/resources/generated/certificatemanager/certificate/index.ts +0 -179
- package/src/providers/aws/cloudControl/resources/generated/kms/key/index.ts +0 -362
- package/src/providers/aws/cloudControl/resources/generated/s3/bucket/index.ts +0 -2364
- package/src/providers/aws/cloudControl/resources/generated/sns/topic/index.ts +0 -326
- package/src/providers/aws/cloudControl/resources/generated/sqs/queue/index.ts +0 -307
- package/src/providers/aws/cloudControl/resources/generated/sqs/queueinlinepolicy/index.ts +0 -108
- package/src/providers/aws/cloudControl/runtime.ts +0 -127
- package/src/providers/aws/management/resourceMapping.ts +0 -343
- package/src/providers/aws/management/resourceOperation.ts +0 -57
- package/src/providers/aws/management/resourcePolicy.ts +0 -549
- package/src/providers/aws/management/resourceRegistration.ts +0 -294
- package/src/providers/aws/resources/apiGatewayV2/httpApi.ts +0 -327
- package/src/providers/aws/resources/generated/native/resourceCommands.ts +0 -152
- package/src/providers/aws/resources/iam/grant.ts +0 -150
- package/src/providers/aws/resources/iam/grantCommands.ts +0 -283
- package/src/providers/aws/resources/iam/policyDocument.ts +0 -30
- package/src/providers/aws/resources/iam/policyStatement.ts +0 -59
- package/src/providers/aws/resources/iam/role.ts +0 -426
- package/src/providers/aws/resources/iam/roleDeclaration.ts +0 -105
- package/src/providers/aws/resources/lambda/function.ts +0 -403
- package/src/providers/aws/resources/lambda/functionDeclaration.ts +0 -234
- package/src/providers/aws/resources/lambda/permission.ts +0 -363
- package/src/providers/aws/resources/stepFunctions/stateMachine.ts +0 -95
- package/src/providers/aws/runtime.ts +0 -70
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Array as Arr,
|
|
3
|
-
Data,
|
|
4
|
-
Effect,
|
|
5
|
-
Layer,
|
|
6
|
-
Match,
|
|
7
|
-
Option,
|
|
8
|
-
Schedule,
|
|
9
|
-
Schema,
|
|
10
|
-
Struct,
|
|
11
|
-
Tuple,
|
|
12
|
-
} from "effect";
|
|
13
|
-
import { Digest } from "effect/crypto";
|
|
14
|
-
import { Base64 } from "effect/encoding";
|
|
15
|
-
import {
|
|
16
|
-
AssetError,
|
|
17
|
-
AssetSchema,
|
|
18
|
-
Assets,
|
|
19
|
-
assetsLayer,
|
|
20
|
-
} from "../../../../core/asset.js";
|
|
21
|
-
import {
|
|
22
|
-
type ResourceCommand,
|
|
23
|
-
ResourceCommandResult,
|
|
24
|
-
ResourceCommandUnsupported,
|
|
25
|
-
ResourceObservation,
|
|
26
|
-
} from "../../../../core/resource/lifecycle.js";
|
|
27
|
-
import {
|
|
28
|
-
ResourceModel,
|
|
29
|
-
type ResourceNode,
|
|
30
|
-
resourceGeneration,
|
|
31
|
-
resourceModelLayer,
|
|
32
|
-
} from "../../../../core/resource/model.js";
|
|
33
|
-
import {
|
|
34
|
-
ResourceCommandExecutionFailed,
|
|
35
|
-
ResourceCommandStackName,
|
|
36
|
-
} from "../../../../core/resource/resourceCommandPolicy.js";
|
|
37
|
-
import { providerCommandPolicyTag } from "../../../resourceCommandPolicyLayer.js";
|
|
38
|
-
import {
|
|
39
|
-
FunctionCode,
|
|
40
|
-
makeLambdaClient,
|
|
41
|
-
} from "../../client/generated/lambda.js";
|
|
42
|
-
import {
|
|
43
|
-
AWSFunctionRequestSchema,
|
|
44
|
-
AWSFunctionResourceSchema,
|
|
45
|
-
} from "../generated/native/lambda/function/index.js";
|
|
46
|
-
|
|
47
|
-
const fields = AWSFunctionRequestSchema.fields;
|
|
48
|
-
/** The settings schema selects the configuration that this native Lambda policy sends on creation and update. */
|
|
49
|
-
const settings = Schema.Struct({
|
|
50
|
-
Description: fields.Description,
|
|
51
|
-
Handler: fields.Handler,
|
|
52
|
-
MemorySize: fields.MemorySize,
|
|
53
|
-
Role: fields.Role,
|
|
54
|
-
Runtime: fields.Runtime,
|
|
55
|
-
Timeout: fields.Timeout,
|
|
56
|
-
});
|
|
57
|
-
const request = settings.pipe(
|
|
58
|
-
Schema.fieldsAssign({
|
|
59
|
-
FunctionName: fields.FunctionName,
|
|
60
|
-
Code: Schema.Union([AssetSchema, fields.Code]),
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
/** The identity schema requires the saved function name before a provider read, update, or deletion. */
|
|
64
|
-
const identity = Schema.Struct({
|
|
65
|
-
FunctionName: Schema.requiredKey(fields.FunctionName),
|
|
66
|
-
});
|
|
67
|
-
const equal = Schema.toEquivalence(Schema.Json);
|
|
68
|
-
const isMissing = (error: { readonly _tag: string; readonly code?: string }) =>
|
|
69
|
-
error._tag === "AwsServiceError" &&
|
|
70
|
-
error.code === "ResourceNotFoundException";
|
|
71
|
-
|
|
72
|
-
/** The FunctionDeploymentFailed error preserves a readiness failure while core retains the saved operation for retry. */
|
|
73
|
-
class FunctionDeploymentFailed extends Data.TaggedError(
|
|
74
|
-
"FunctionDeploymentFailed",
|
|
75
|
-
)<{
|
|
76
|
-
readonly logicalId: string;
|
|
77
|
-
readonly message: string;
|
|
78
|
-
}> {}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The functionCommands Layer creates functions from planned assets and updates
|
|
82
|
-
* configuration before code. Each mutation waits up to three minutes for
|
|
83
|
-
* readiness. Local code must match the reported CodeSha256 before core saves
|
|
84
|
-
* the applied declaration. Removing a saved configuration field fails before
|
|
85
|
-
* mutation because this policy has no reset values for those fields.
|
|
86
|
-
*
|
|
87
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (CreateFunction, UpdateFunctionConfiguration, UpdateFunctionCode, FunctionConfiguration.CodeSha256)
|
|
88
|
-
* @see ../../../../../node_modules/effect/src/Effect.ts (repeat and retry)
|
|
89
|
-
*/
|
|
90
|
-
export const functionCommands = Layer.effect(
|
|
91
|
-
providerCommandPolicyTag(AWSFunctionResourceSchema),
|
|
92
|
-
Effect.gen(function* () {
|
|
93
|
-
const client = yield* makeLambdaClient;
|
|
94
|
-
const model = yield* ResourceModel;
|
|
95
|
-
const assets = yield* Assets;
|
|
96
|
-
const digest = yield* Digest.Digest;
|
|
97
|
-
|
|
98
|
-
/** The read function returns validated provider outputs or absence when Lambda reports ResourceNotFoundException. */
|
|
99
|
-
const read = Effect.fn("Function.read")(function* (node: ResourceNode) {
|
|
100
|
-
const key = yield* Schema.decodeUnknownEffect(identity)(node.outputs);
|
|
101
|
-
|
|
102
|
-
return yield* client.getFunctionConfiguration(key).pipe(
|
|
103
|
-
Effect.flatMap((observed) =>
|
|
104
|
-
model
|
|
105
|
-
.withObservedOutputs(
|
|
106
|
-
node,
|
|
107
|
-
Struct.assign(observed, { Arn: observed.FunctionArn }),
|
|
108
|
-
)
|
|
109
|
-
.pipe(Effect.map((node) => ({ node, observed }))),
|
|
110
|
-
),
|
|
111
|
-
Effect.map(Option.some),
|
|
112
|
-
Effect.catchIf(isMissing, () => Effect.succeedNone),
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The waitForConfiguration function waits for an active function with no
|
|
118
|
-
* update in progress. Lambda's failure reason remains in the typed error;
|
|
119
|
-
* timeout and interruption stop the local polling.
|
|
120
|
-
*
|
|
121
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (GetFunctionConfiguration and FunctionConfiguration)
|
|
122
|
-
* @see ../../../../../node_modules/effect/src/Effect.ts (repeat and timeout)
|
|
123
|
-
*/
|
|
124
|
-
const waitForConfiguration = Effect.fn("Function.waitForConfiguration")(
|
|
125
|
-
function* (node: ResourceNode) {
|
|
126
|
-
const key = yield* Schema.decodeUnknownEffect(identity)(node.outputs);
|
|
127
|
-
|
|
128
|
-
const observed = yield* client.getFunctionConfiguration(key).pipe(
|
|
129
|
-
Effect.repeat({
|
|
130
|
-
while: (value) =>
|
|
131
|
-
value.State === "Pending" ||
|
|
132
|
-
value.LastUpdateStatus === "InProgress",
|
|
133
|
-
schedule: Schedule.spaced("1 second"),
|
|
134
|
-
}),
|
|
135
|
-
Effect.timeout("3 minutes"),
|
|
136
|
-
Effect.filterOrFail(
|
|
137
|
-
(value) =>
|
|
138
|
-
value.State === "Active" && value.LastUpdateStatus !== "Failed",
|
|
139
|
-
(value) =>
|
|
140
|
-
new FunctionDeploymentFailed({
|
|
141
|
-
logicalId: node.key.logicalId,
|
|
142
|
-
message: `Function ${key.FunctionName} failed to become ready: ${value.LastUpdateStatusReason ?? value.StateReason ?? value.State}.`,
|
|
143
|
-
}),
|
|
144
|
-
),
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
return observed;
|
|
148
|
-
},
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
/** The waitFor function checks the planned asset digest after readiness and returns the validated node that core can persist. */
|
|
152
|
-
const waitFor = Effect.fn("Function.waitFor")(function* (
|
|
153
|
-
node: ResourceNode,
|
|
154
|
-
) {
|
|
155
|
-
const observed = yield* waitForConfiguration(node);
|
|
156
|
-
const props = yield* model.decodeProps(node, Schema.JsonObject);
|
|
157
|
-
|
|
158
|
-
yield* Effect.fail(
|
|
159
|
-
new FunctionDeploymentFailed({
|
|
160
|
-
logicalId: node.key.logicalId,
|
|
161
|
-
message: `Function ${observed.FunctionName} reports a different code digest. Saved state was kept.`,
|
|
162
|
-
}),
|
|
163
|
-
).pipe(
|
|
164
|
-
Effect.when(
|
|
165
|
-
Effect.succeed(
|
|
166
|
-
Schema.is(AssetSchema)(props.Code) &&
|
|
167
|
-
props.Code.digest !== observed.CodeSha256,
|
|
168
|
-
),
|
|
169
|
-
),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const ready: ResourceNode = yield* model.withObservedOutputs(
|
|
173
|
-
node,
|
|
174
|
-
Struct.assign(observed, { Arn: observed.FunctionArn }),
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
return ready;
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* The codeInput function encodes retained asset bytes for a direct upload,
|
|
182
|
-
* rejecting archives above 50 MiB. Other code locations pass through the
|
|
183
|
-
* generated FunctionCode schema before the client receives them.
|
|
184
|
-
*
|
|
185
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (FunctionCode.ZipFile)
|
|
186
|
-
*/
|
|
187
|
-
const codeInput = Effect.fn("Function.codeInput")(function* (
|
|
188
|
-
code: (typeof request.Type)["Code"],
|
|
189
|
-
) {
|
|
190
|
-
const asset = Option.liftPredicate(code, Schema.is(AssetSchema));
|
|
191
|
-
const bytes = yield* asset.pipe(
|
|
192
|
-
Option.map(assets.bytes),
|
|
193
|
-
Effect.transposeOption,
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
yield* Effect.fail(
|
|
197
|
-
new AssetError({
|
|
198
|
-
path: "Code",
|
|
199
|
-
message: "The code asset exceeds the direct upload limit of 50 MiB.",
|
|
200
|
-
}),
|
|
201
|
-
).pipe(
|
|
202
|
-
Effect.when(
|
|
203
|
-
Effect.succeed(
|
|
204
|
-
Option.exists(
|
|
205
|
-
bytes,
|
|
206
|
-
(bytes) => bytes.byteLength > 50 * 1024 * 1024,
|
|
207
|
-
),
|
|
208
|
-
),
|
|
209
|
-
),
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
return yield* Option.match(bytes, {
|
|
213
|
-
onSome: (bytes) => Effect.succeed({ ZipFile: Base64.encode(bytes) }),
|
|
214
|
-
onNone: () => Schema.decodeUnknownEffect(FunctionCode)(code),
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* The create function uses an explicit name or derives one from the stack,
|
|
220
|
-
* logical ID, and generation. A new IAM role can take time to become
|
|
221
|
-
* assumable; the documented assume-role rejection is retried for up to
|
|
222
|
-
* three minutes before creation fails.
|
|
223
|
-
*/
|
|
224
|
-
const create = Effect.fn("Function.create")(function* (node: ResourceNode) {
|
|
225
|
-
const props = yield* model.decodeProps(node, request);
|
|
226
|
-
const configuration = yield* Schema.decodeUnknownEffect(settings)(props);
|
|
227
|
-
const code = yield* codeInput(props.Code);
|
|
228
|
-
|
|
229
|
-
const FunctionName = yield* Option.fromUndefinedOr(
|
|
230
|
-
props.FunctionName,
|
|
231
|
-
).pipe(
|
|
232
|
-
Effect.fromOption,
|
|
233
|
-
Effect.catch(() =>
|
|
234
|
-
ResourceCommandStackName.pipe(
|
|
235
|
-
Effect.flatMap(Effect.fromOption),
|
|
236
|
-
Effect.map((stack) =>
|
|
237
|
-
Tuple.make(stack, node.key.logicalId, resourceGeneration(node)),
|
|
238
|
-
),
|
|
239
|
-
Effect.flatMap(
|
|
240
|
-
Schema.encodeEffect(Schema.fromJsonString(Schema.Json)),
|
|
241
|
-
),
|
|
242
|
-
Effect.flatMap((seed) =>
|
|
243
|
-
digest.digestHex(Digest.sha256, new TextEncoder().encode(seed)),
|
|
244
|
-
),
|
|
245
|
-
Effect.map((hash) => `nomoss-${hash.substring(0, 56)}`),
|
|
246
|
-
),
|
|
247
|
-
),
|
|
248
|
-
);
|
|
249
|
-
const created = yield* client
|
|
250
|
-
.createFunction(
|
|
251
|
-
Struct.assign(configuration, { FunctionName, Code: code }),
|
|
252
|
-
)
|
|
253
|
-
.pipe(
|
|
254
|
-
Effect.retry({
|
|
255
|
-
while: (error) =>
|
|
256
|
-
error._tag === "AwsServiceError" &&
|
|
257
|
-
error.code === "InvalidParameterValueException" &&
|
|
258
|
-
error.message.includes(
|
|
259
|
-
"The role defined for the function cannot be assumed by Lambda",
|
|
260
|
-
),
|
|
261
|
-
schedule: Schedule.spaced("1 second").pipe(
|
|
262
|
-
Schedule.upTo({ duration: "3 minutes" }),
|
|
263
|
-
),
|
|
264
|
-
}),
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
const identified = yield* model.withOutputs(node, {
|
|
268
|
-
FunctionName: created.FunctionName ?? FunctionName,
|
|
269
|
-
});
|
|
270
|
-
const ready = yield* waitFor(identified);
|
|
271
|
-
|
|
272
|
-
const result: ResourceCommandResult = ResourceCommandResult.Created({
|
|
273
|
-
node: ready,
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
return result;
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* The update function changes configuration and code only when their
|
|
281
|
-
* saved inputs differ. Configuration must finish before code can change.
|
|
282
|
-
* The returned node confirms readiness and the planned local code digest.
|
|
283
|
-
*/
|
|
284
|
-
const update = Effect.fn("Function.update")(function* (
|
|
285
|
-
node: ResourceNode,
|
|
286
|
-
current: ResourceNode,
|
|
287
|
-
) {
|
|
288
|
-
const props = yield* model.decodeProps(node, request);
|
|
289
|
-
const configuration = yield* Schema.decodeUnknownEffect(settings)(props);
|
|
290
|
-
const code = yield* codeInput(props.Code);
|
|
291
|
-
const saved = yield* model.decodeProps(current, request);
|
|
292
|
-
const previous = yield* Schema.decodeUnknownEffect(settings)(saved);
|
|
293
|
-
const key = yield* Schema.decodeUnknownEffect(identity)(current.outputs);
|
|
294
|
-
|
|
295
|
-
yield* Effect.fail(
|
|
296
|
-
new ResourceCommandUnsupported({
|
|
297
|
-
command: {
|
|
298
|
-
_tag: "Apply",
|
|
299
|
-
decision: { _tag: "Update", node, current },
|
|
300
|
-
},
|
|
301
|
-
}),
|
|
302
|
-
).pipe(
|
|
303
|
-
Effect.when(
|
|
304
|
-
Effect.succeed(
|
|
305
|
-
Arr.some(
|
|
306
|
-
Struct.keys(previous),
|
|
307
|
-
(key) => !Arr.contains(Struct.keys(configuration), key),
|
|
308
|
-
),
|
|
309
|
-
),
|
|
310
|
-
),
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
const identified = yield* model.withOutputs(node, current.outputs);
|
|
314
|
-
const configChanged = !equal(configuration, previous);
|
|
315
|
-
const codeChanged = !equal(props.Code, saved.Code);
|
|
316
|
-
|
|
317
|
-
// The UpdateFunctionConfiguration operation completes before the code
|
|
318
|
-
// mutation starts. GetFunctionConfiguration supplies the status fields
|
|
319
|
-
// described by the pinned model's UpdateFunctionConfiguration guide.
|
|
320
|
-
yield* client
|
|
321
|
-
.updateFunctionConfiguration(Struct.assign(configuration, key))
|
|
322
|
-
.pipe(
|
|
323
|
-
Effect.andThen(() => waitForConfiguration(identified)),
|
|
324
|
-
Effect.when(Effect.succeed(configChanged)),
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
yield* client
|
|
328
|
-
.updateFunctionCode(Struct.assign(code, key))
|
|
329
|
-
.pipe(Effect.when(Effect.succeed(codeChanged)));
|
|
330
|
-
|
|
331
|
-
const ready = yield* waitFor(identified);
|
|
332
|
-
|
|
333
|
-
const result: ResourceCommandResult = ResourceCommandResult.Updated({
|
|
334
|
-
node: ready,
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
return result;
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
/** The destroy function removes the saved function and confirms absence before returning; an already missing function also completes deletion. */
|
|
341
|
-
const destroy = Effect.fn("Function.destroy")(function* (
|
|
342
|
-
node: ResourceNode,
|
|
343
|
-
) {
|
|
344
|
-
const key = yield* Schema.decodeUnknownEffect(identity)(node.outputs);
|
|
345
|
-
|
|
346
|
-
yield* client
|
|
347
|
-
.deleteFunction(key)
|
|
348
|
-
.pipe(Effect.catchIf(isMissing, () => Effect.void));
|
|
349
|
-
|
|
350
|
-
yield* read(node).pipe(
|
|
351
|
-
Effect.repeat({
|
|
352
|
-
while: Option.isSome,
|
|
353
|
-
schedule: Schedule.spaced("1 second"),
|
|
354
|
-
}),
|
|
355
|
-
Effect.timeout("3 minutes"),
|
|
356
|
-
);
|
|
357
|
-
|
|
358
|
-
const result: ResourceCommandResult = ResourceCommandResult.Destroyed({
|
|
359
|
-
node,
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
return result;
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
/** The execute service method dispatches supported lifecycle commands and preserves provider or validation failures inside ResourceCommandExecutionFailed. */
|
|
366
|
-
const execute = Effect.fn("Function.execute")((command: ResourceCommand) =>
|
|
367
|
-
Match.value(command).pipe(
|
|
368
|
-
Match.tag("Read", ({ node }) =>
|
|
369
|
-
read(node).pipe(
|
|
370
|
-
Effect.map((value) => {
|
|
371
|
-
const observation = Option.match(value, {
|
|
372
|
-
onNone: () => ResourceObservation.Missing({ node }),
|
|
373
|
-
onSome: ResourceObservation.Present,
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
return ResourceCommandResult.Observed({ observation });
|
|
377
|
-
}),
|
|
378
|
-
),
|
|
379
|
-
),
|
|
380
|
-
Match.tag("Create", ({ node }) => create(node)),
|
|
381
|
-
Match.tag("Delete", "Destroy", ({ node }) => destroy(node)),
|
|
382
|
-
Match.tag("Apply", ({ decision }) =>
|
|
383
|
-
Match.value(decision).pipe(
|
|
384
|
-
Match.tag("Create", ({ node }) => create(node)),
|
|
385
|
-
Match.tag("Update", ({ node, current }) => update(node, current)),
|
|
386
|
-
Match.tag("Delete", "Destroy", ({ node }) => destroy(node)),
|
|
387
|
-
Match.orElse(() =>
|
|
388
|
-
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
389
|
-
),
|
|
390
|
-
),
|
|
391
|
-
),
|
|
392
|
-
Match.orElse(() =>
|
|
393
|
-
Effect.fail(new ResourceCommandUnsupported({ command })),
|
|
394
|
-
),
|
|
395
|
-
Effect.mapError(
|
|
396
|
-
(cause) => new ResourceCommandExecutionFailed({ command, cause }),
|
|
397
|
-
),
|
|
398
|
-
),
|
|
399
|
-
);
|
|
400
|
-
|
|
401
|
-
return { execute };
|
|
402
|
-
}),
|
|
403
|
-
).pipe(Layer.provide([resourceModelLayer, assetsLayer, Digest.layerWebCrypto]));
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { Effect, Match, Schema, Struct } from "effect";
|
|
2
|
-
import { AssetSchema } from "../../../../core/asset.js";
|
|
3
|
-
import type { ResourceKey } from "../../../../core/resource/model.js";
|
|
4
|
-
import { annotateResourceSchema } from "../../../../core/resource/model.js";
|
|
5
|
-
import { ResourceGraphBuilder } from "../../../../core/resource/resourceGraphBuilder.js";
|
|
6
|
-
import { ResourceGraphStore } from "../../../../core/resource/resourceGraphStore.js";
|
|
7
|
-
import type { ResourceOutputBinding } from "../../../../core/resource/resourceOutputBinding.js";
|
|
8
|
-
import { AWSRouteResource } from "../generated/native/apigatewayv2/route/index.js";
|
|
9
|
-
import {
|
|
10
|
-
AWSFunctionOutputsSchema,
|
|
11
|
-
AWSFunctionPropsSchema,
|
|
12
|
-
AWSFunctionRequestSchema,
|
|
13
|
-
AWSFunctionResourceSchema,
|
|
14
|
-
AWSFunctionResourceTypeSchema,
|
|
15
|
-
AWSFunctionResource as GeneratedFunction,
|
|
16
|
-
} from "../generated/native/lambda/function/index.js";
|
|
17
|
-
import {
|
|
18
|
-
AWSPermission,
|
|
19
|
-
type AWSPermissionProps,
|
|
20
|
-
} from "../generated/native/lambda/permission/index.js";
|
|
21
|
-
import { AWSRole, type AWSRoleResource } from "../iam/roleDeclaration.js";
|
|
22
|
-
import { routeInvocationPermission } from "./permission.js";
|
|
23
|
-
|
|
24
|
-
export * from "../generated/native/lambda/function/index.js";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The LambdaExecutionRole function creates a role Lambda can assume
|
|
28
|
-
* and gives it permission to write CloudWatch Logs. IAM installs the inline
|
|
29
|
-
* policy as part of role creation, so a function that uses this role waits
|
|
30
|
-
* for both trust and logging permissions.
|
|
31
|
-
*
|
|
32
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (CreateFunction and CreateFunctionRequest.Role)
|
|
33
|
-
*/
|
|
34
|
-
export const LambdaExecutionRole = (logicalId: string) =>
|
|
35
|
-
AWSRole({
|
|
36
|
-
logicalId,
|
|
37
|
-
props: {
|
|
38
|
-
AssumeRolePolicyDocument: {
|
|
39
|
-
Version: "2012-10-17",
|
|
40
|
-
Statement: [
|
|
41
|
-
{
|
|
42
|
-
Effect: "Allow",
|
|
43
|
-
Principal: { Service: "lambda.amazonaws.com" },
|
|
44
|
-
Action: "sts:AssumeRole",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
Policies: [
|
|
49
|
-
{
|
|
50
|
-
PolicyName: "CloudWatchLogs",
|
|
51
|
-
PolicyDocument: {
|
|
52
|
-
Version: "2012-10-17",
|
|
53
|
-
Statement: [
|
|
54
|
-
{
|
|
55
|
-
Effect: "Allow",
|
|
56
|
-
Action: [
|
|
57
|
-
"logs:CreateLogGroup",
|
|
58
|
-
"logs:CreateLogStream",
|
|
59
|
-
"logs:PutLogEvents",
|
|
60
|
-
],
|
|
61
|
-
Resource: "*",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const functionProps = annotateResourceSchema(
|
|
71
|
-
AWSFunctionPropsSchema.pipe(
|
|
72
|
-
Schema.fieldsAssign({
|
|
73
|
-
Code: Schema.Union([AssetSchema, AWSFunctionPropsSchema.fields.Code]),
|
|
74
|
-
}),
|
|
75
|
-
),
|
|
76
|
-
AWSFunctionResourceSchema,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const functionRequest = AWSFunctionRequestSchema.pipe(
|
|
80
|
-
Schema.fieldsAssign({
|
|
81
|
-
Code: Schema.Union([AssetSchema, AWSFunctionRequestSchema.fields.Code]),
|
|
82
|
-
}),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
type FunctionProps = typeof functionProps.Type;
|
|
86
|
-
|
|
87
|
-
type FunctionDeclaration = {
|
|
88
|
-
readonly logicalId: string;
|
|
89
|
-
} & (
|
|
90
|
-
| { readonly executionRole?: never; readonly props: FunctionProps }
|
|
91
|
-
| {
|
|
92
|
-
readonly executionRole: AWSRoleResource;
|
|
93
|
-
readonly props: Omit<FunctionProps, "Role"> & { readonly Role?: never };
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
type LambdaPermission = {
|
|
98
|
-
readonly [Field in Exclude<
|
|
99
|
-
keyof AWSPermissionProps,
|
|
100
|
-
"FunctionName"
|
|
101
|
-
> as Field extends "PrincipalOrgID"
|
|
102
|
-
? "principalOrgId"
|
|
103
|
-
: Uncapitalize<Field>]: AWSPermissionProps[Field];
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const permissionKeys = {
|
|
107
|
-
action: "Action",
|
|
108
|
-
eventSourceToken: "EventSourceToken",
|
|
109
|
-
functionUrlAuthType: "FunctionUrlAuthType",
|
|
110
|
-
invokedViaFunctionUrl: "InvokedViaFunctionUrl",
|
|
111
|
-
principal: "Principal",
|
|
112
|
-
principalOrgId: "PrincipalOrgID",
|
|
113
|
-
sourceAccount: "SourceAccount",
|
|
114
|
-
sourceArn: "SourceArn",
|
|
115
|
-
} as const;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The AWSFunctionResource class lets an application declare permissions for
|
|
119
|
-
* callers of a native Lambda function.
|
|
120
|
-
*/
|
|
121
|
-
export class AWSFunctionResource<
|
|
122
|
-
Props = FunctionProps,
|
|
123
|
-
> extends GeneratedFunction<Props> {
|
|
124
|
-
/**
|
|
125
|
-
* The grantInvoke method lets a role in the same account invoke this
|
|
126
|
-
* unqualified function or lets API Gateway invoke it for a concrete HTTP
|
|
127
|
-
* route with a literal path. Route parameters, wildcards, ANY, and $default
|
|
128
|
-
* fail schema validation; addPermission accepts an explicit sourceArn for
|
|
129
|
-
* those cases. Removing the grant declaration removes its policy statement.
|
|
130
|
-
*
|
|
131
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (Invoke)
|
|
132
|
-
* @see ../../../../../docs/application/resource-graph.md (Relationships and request values)
|
|
133
|
-
*/
|
|
134
|
-
grantInvoke(
|
|
135
|
-
role: AWSRoleResource,
|
|
136
|
-
): ReturnType<AWSRoleResource["addToPolicy"]>;
|
|
137
|
-
grantInvoke(
|
|
138
|
-
route: AWSRouteResource,
|
|
139
|
-
): ReturnType<typeof routeInvocationPermission>;
|
|
140
|
-
grantInvoke(grantee: AWSRoleResource | AWSRouteResource) {
|
|
141
|
-
return Match.value(grantee).pipe(
|
|
142
|
-
Match.when(
|
|
143
|
-
(candidate): candidate is AWSRouteResource =>
|
|
144
|
-
candidate instanceof AWSRouteResource,
|
|
145
|
-
(route) => routeInvocationPermission(this, route),
|
|
146
|
-
),
|
|
147
|
-
Match.orElse((role) =>
|
|
148
|
-
role.addToPolicy(
|
|
149
|
-
`LambdaInvoke/${encodeURIComponent(this.key.logicalId)}`,
|
|
150
|
-
{ actions: ["lambda:InvokeFunction"], resources: [this] },
|
|
151
|
-
),
|
|
152
|
-
),
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* The addPermission method declares a named statement on the receiving
|
|
158
|
-
* function. Use sourceArn or sourceAccount to restrict a service principal
|
|
159
|
-
* to the resources that may invoke the function.
|
|
160
|
-
*
|
|
161
|
-
* @see ../../../../../refs/aws-api-models/models/lambda/service/2015-03-31/lambda-2015-03-31.json (AddPermissionRequest)
|
|
162
|
-
* @see ../../../../../../command-options-fund/refs/effect/packages/effect/src/Struct.ts (renameKeys)
|
|
163
|
-
*/
|
|
164
|
-
addPermission(name: string, permission: LambdaPermission) {
|
|
165
|
-
return Schema.decodeEffect(Schema.NonEmptyString)(name).pipe(
|
|
166
|
-
Effect.flatMap((statement) =>
|
|
167
|
-
AWSPermission({
|
|
168
|
-
logicalId: `${this.key.logicalId}/Permission/${encodeURIComponent(statement)}`,
|
|
169
|
-
props: Struct.assign(Struct.renameKeys(permission, permissionKeys), {
|
|
170
|
-
FunctionName: this,
|
|
171
|
-
}),
|
|
172
|
-
}),
|
|
173
|
-
),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* The createAWSFunctionDeclaration function constructs a Lambda entity from
|
|
180
|
-
* validated properties. Its stack binding supplies applied output values.
|
|
181
|
-
*/
|
|
182
|
-
export const createAWSFunctionDeclaration = <Props>(
|
|
183
|
-
key: ResourceKey,
|
|
184
|
-
props: Props,
|
|
185
|
-
binding?: ResourceOutputBinding,
|
|
186
|
-
) => new AWSFunctionResource(key, props, binding);
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* The AWSFunction function registers a native Lambda function with invocation
|
|
190
|
-
* grants. Pass an Asset as Code to build or package local source during planning.
|
|
191
|
-
* Supply an executionRole to depend on a declared IAM role. Core resolves
|
|
192
|
-
* its ARN after role creation through the generated relationship schema.
|
|
193
|
-
*
|
|
194
|
-
* @see ../../../../../docs/application/resource-graph.md (Relationships and request values)
|
|
195
|
-
* @see ../../../../../refs/aws-cdk-generator/packages/aws-cdk-lib/core/lib/assets.ts (FileAssetSource)
|
|
196
|
-
* @see ../../../../../node_modules/effect/src/Schema.ts (fieldsAssign)
|
|
197
|
-
*/
|
|
198
|
-
export const AWSFunction = Effect.fn("AWSFunction")(function* (
|
|
199
|
-
input: FunctionDeclaration,
|
|
200
|
-
) {
|
|
201
|
-
const graph = yield* ResourceGraphStore;
|
|
202
|
-
const binding = yield* graph.outputBinding;
|
|
203
|
-
|
|
204
|
-
const declaration = Match.value(input).pipe(
|
|
205
|
-
Match.when(
|
|
206
|
-
{ executionRole: Match.defined },
|
|
207
|
-
({ logicalId, props, executionRole }) => ({
|
|
208
|
-
logicalId,
|
|
209
|
-
props: Struct.assign(props, { Role: executionRole }),
|
|
210
|
-
}),
|
|
211
|
-
),
|
|
212
|
-
Match.orElse(({ logicalId, props }) => ({ logicalId, props })),
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
const builder = yield* ResourceGraphBuilder;
|
|
216
|
-
const key: ResourceKey = { logicalId: declaration.logicalId };
|
|
217
|
-
const registration = yield* builder.resource(key);
|
|
218
|
-
const props = yield* Schema.decodeEffect(functionProps)(declaration.props);
|
|
219
|
-
|
|
220
|
-
yield* registration.registerEntity(AWSFunctionResourceTypeSchema, {
|
|
221
|
-
propsSchema: functionProps,
|
|
222
|
-
requestSchema: functionRequest,
|
|
223
|
-
outputsSchema: AWSFunctionOutputsSchema,
|
|
224
|
-
props,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
const resource: AWSFunctionResource = createAWSFunctionDeclaration(
|
|
228
|
-
key,
|
|
229
|
-
props,
|
|
230
|
-
binding,
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
return resource;
|
|
234
|
-
});
|