Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassaku63/ec6ffc7f97bca473eb7472d5b1faebce to your computer and use it in GitHub Desktop.
Save hassaku63/ec6ffc7f97bca473eb7472d5b1faebce to your computer and use it in GitHub Desktop.
AWS SDK for Node.js (v3) で CodePipeline StartPipelineExecution API を実行するサンプル
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