| 1 | import * as appintegrations from "@distilled.cloud/aws/appintegrations"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import * as Output from "../../Output.ts"; |
| 4 | import { makeAppIntegrationsHttpBinding } from "./BindingHttp.ts"; |
| 5 | import { CreateDataIntegrationAssociation } from "./CreateDataIntegrationAssociation.ts"; |
| 6 | import type { DataIntegration } from "./DataIntegration.ts"; |
| 7 | |
| 8 | /** |
| 9 | * HTTP implementation of {@link CreateDataIntegrationAssociation}. At deploy |
| 10 | * time it grants `app-integrations:CreateDataIntegrationAssociation` on the |
| 11 | * data integration (and its `data-integration-association/*` children); at |
| 12 | * runtime it calls the AppIntegrations API with the host Function's |
| 13 | * credentials, injecting the data integration's id. Provide this layer on |
| 14 | * the Function using the binding. |
| 15 | */ |
| 16 | export const CreateDataIntegrationAssociationHttp = Layer.effect( |
| 17 | CreateDataIntegrationAssociation, |
| 18 | makeAppIntegrationsHttpBinding({ |
| 19 | name: "CreateDataIntegrationAssociation", |
| 20 | operation: appintegrations.createDataIntegrationAssociation, |
| 21 | requestKey: "DataIntegrationIdentifier", |
| 22 | identifier: (integration: DataIntegration) => integration.dataIntegrationId, |
| 23 | iamActions: ["app-integrations:CreateDataIntegrationAssociation"], |
| 24 | resources: (integration, { region, accountId }) => [ |
| 25 | Output.interpolate`${integration.dataIntegrationArn}`, |
| 26 | Output.interpolate`arn:aws:app-integrations:${region}:${accountId}:data-integration-association/${integration.dataIntegrationId}/*`, |
| 27 | ], |
| 28 | // AppIntegrations provisions an AppFlow flow (and Customer Profiles |
| 29 | // snapshots) on the caller's behalf when an association is created. |
| 30 | dependentActions: [ |
| 31 | "appflow:CreateFlow", |
| 32 | "appflow:DeleteFlow", |
| 33 | "appflow:DescribeConnectorEntity", |
| 34 | "appflow:DescribeConnectorProfiles", |
| 35 | "appflow:TagResource", |
| 36 | "appflow:UseConnectorProfile", |
| 37 | "profile:CreateSnapshot", |
| 38 | "profile:GetSnapshot", |
| 39 | ], |
| 40 | }), |
| 41 | ); |