- Newest
- Most votes
- Most comments
I do not believe that the response above is accurate as the connection property seems to not want a string:
Type 'string' is not assignable to type 'IConnection'.
I know this is how you would approach it within the console but via CDK it seems to either require a different approach or not be possible.
answered 2 years ago
Yeah this answer doesn't make sense. AI fail.
This is a real pain too as the alternative is to create a lambda to make http requests but adds complexity which HttpInvoke should abstract away..
answered a year ago
Yes, it is possible to configure the StateMachine's HttpInvoke Connection as a runtime input using AWS CDK, although it requires a slightly different approach than directly setting the Connection property at build time.
To achieve this, you can use the AWS Step Functions Task construct with the "arn:aws:states:::http:invoke" resource and utilize JsonPath to dynamically set the Connection at runtime. Here's how you can approach this:
-
Instead of specifying the Connection directly in the CDK code, you'll need to pass it as part of the input to your State Machine execution.
-
In your CDK code, when defining the HttpInvoke task, you can use JsonPath to reference the Connection that will be provided at runtime. For example:
const httpInvoke = new tasks.HttpInvoke(this, 'HttpInvoke', { apiEndpoint: JsonPath.stringAt('$.apiEndpoint'), httpMethod: HttpMethod.POST, connection: JsonPath.stringAt('$.connection'), // other properties as needed }); -
When you execute the State Machine, you'll need to provide the Connection ARN as part of the input. For example:
{ "tenantId": "tenant1", "connection": "arn:aws:events:us-east-1:123456789012:connection/tenant1-airtable", "apiEndpoint": "/some/endpoint" }
This approach allows you to dynamically specify the Connection based on the Tenant ID at runtime, while still defining the structure of your State Machine using CDK.
Remember to ensure that your State Machine's IAM role has the necessary permissions to use all the potential Connections that might be passed in at runtime.
Also, note that while this method provides flexibility, it also means that you're deferring some of the configuration to runtime, which can make it harder to validate the correctness of your State Machine at build time. Make sure to implement proper error handling and input validation in your State Machine to account for potential runtime issues.
Sources
interface HttpInvokeProps · AWS CDK
interface HttpIntegrationProps · AWS CDK
Call HTTPS APIs in Step Functions workflows - AWS Step Functions
