Reputation: 1
I am working with Data sync start execution Api. I have One stack in which I am creating all the locations, Tasks, Role and I am using DataSync client with startExecutionApi to call the task in the same stack.
My code Snippet for dataSync looks something like this
const client = new DataSyncClient();
const input = {
TaskArn: TASK1.attrTaskArn,
};
const command = new StartTaskExecutionCommand(input);
(async () => {
const response = await client.send(command);
})();
But I am getting below Error
const exception = new InvalidRequestException({ ^ InvalidRequestException: Invalid parameter: Malformed ARN: ${Token[TOKEN.110]}. at de_InvalidRequestExceptionRes (/codebuild/output/src4271555059/src/node_modules/@aws-sdk/client-datasync/dist-cjs/index.js:1945:21) at de_CommandError (/codebuild/output/src4271555059/src/node_modules/@aws-sdk/client-datasync/dist-cjs/index.js:1923:19) at processTicksAndRejections (node:internal/process/task_queues:95:5) at async /codebuild/output/src4271555059/src/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20 at async /codebuild/output/src4271555059/src/node_modules/@smithy/core/dist-cjs/index.js:165:18 at async /codebuild/output/src4271555059/src/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38 at async /codebuild/output/src4271555059/src/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22 at async /codebuild/output/src4271555059/src/lib/stacks/be-customer-migration-stack.ts:65:28 { '$fault': 'client', '$metadata': { httpStatusCode: 400, requestId: 'b124d220-8350-4bc5-9cb1-219211c65fea', extendedRequestId: undefined, cfId: undefined, attempts: 1, totalRetryDelay: 0 }, errorCode: 'InvalidParameter', datasyncErrorCode: undefined, __type: 'InvalidRequestException' }
I tried few things and I observed
If I hard code TASK1.attrTaskArn with the task arn, that has been already created and then print the response. I get 200 Ok; the task also gets triggered during the synth stage of my pipeline. (Info:-> I use pipeline to deploy the stack, and not directly deploy it)
From what I have found through some research is that, datasync client is not able to resolve the arn token at the time of deployment.
Is it because both task creation and execution are being done at the same time?
Is there any way to do both of them in same stack?
Upvotes: 0
Views: 59
Reputation: 1
I found my answer in aws repost It was because I am making an AWS SDK call in your CDK application code. Need to change it to either custom resource or add additional steps to my pipeline. I Will post the code snippet Once I am done with it. https://repost.aws/questions/QUjGdb9lxbTeSuMKcMUMyWPg/datasync-start-execution-api
EDIT:-> I created a custom function to invoke the task every time I deploy the stack
const uniqueId = Date.now().toString();
new cr.AwsCustomResource(this, `${uniqueId}-CustomResource1`, {
onCreate: {
service: 'DataSync',
action: 'startTaskExecution',
parameters: {
TaskArn: taskArn,
},
physicalResourceId: cr.PhysicalResourceId.of(`CustomResource1-${Math.random().toString(36).substring(2, 15)}`),
},
onUpdate: {
service: 'DataSync',
action: 'startTaskExecution',
parameters: {
TaskArn: taskArn,
},
physicalResourceId: cr.PhysicalResourceId.of(`CustomResource1-${Math.random().toString(36).substring(2, 15)}`),
},
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({ resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE }),
role: customResourceRole,
});
Upvotes: 0