Created
June 19, 2023 12:35
-
-
Save hassaku63/ec6ffc7f97bca473eb7472d5b1faebce to your computer and use it in GitHub Desktop.
AWS SDK for Node.js (v3) で CodePipeline StartPipelineExecution API を実行するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
CodePipelineClient, | |
StartPipelineExecutionCommand, | |
StartPipelineExecutionCommandOutput, | |
ConflictException, | |
} from "@aws-sdk/client-codepipeline"; | |
type StartPipelineExecutionResultFailed = { | |
success: false, | |
error: Error, | |
} | |
type StartPipelineExecutionResultSucceeded = { | |
success: true, | |
result: StartPipelineExecutionCommandOutput, | |
} | |
type StartPipelineExecutionResult = StartPipelineExecutionResultFailed | StartPipelineExecutionResultSucceeded; | |
async function startCodePipelineExecution( | |
pipelineName: string | |
): Promise<StartPipelineExecutionResult> { | |
const client = new CodePipelineClient({}); | |
const command = new StartPipelineExecutionCommand({ | |
name: pipelineName, | |
}) | |
try { | |
const result = await client.send(command); | |
return { | |
success: true, | |
result | |
}; | |
} catch (error) { | |
if (error instanceof ConflictException) { | |
return { | |
success: false, | |
error, | |
}; | |
} | |
/** | |
* 次の 3つの例外が発生しうるが、これは予期していないエラーであり | |
* 実行時の修復も不可能と判断した。エラーハンドリングの余地は残さない。 | |
* | |
* PipelineNotFoundException, | |
* ValidationException, | |
* CodePipelineServiceException, | |
*/ | |
throw error; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment