0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS Batch SDK for .Net

Posted at
using System;
using System.Threading.Tasks;
using Amazon.Batch;
using Amazon.Batch.Model;
using Amazon.Runtime;

namespace AWSBatchJobSubmission
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // AWS認証情報を設定
            var awsCredentials = new SessionAWSCredentials(
                "YOUR_ACCESS_KEY",  // アクセスキー
                "YOUR_SECRET_KEY",  // シークレットキー
                "YOUR_SESSION_TOKEN" // セッショントークン
            );
            
            // AWS Batchクライアントの作成
            var batchClient = new AmazonBatchClient(awsCredentials, Amazon.RegionEndpoint.USEast1);

            var submitJobRequest = new SubmitJobRequest
            {
                JobName = "JOB_NAME", // ジョブ名
                JobQueue = "JOB_QUEUE_NAME", // ジョブキュー
                JobDefinition = "JOB_DEFINITION_NAME", // ジョブ定義
                ContainerOverrides = new ContainerOverrides
                {
                    // コンテナで実行するコマンドを指定
                    //Command = new List<string> { "echo", "Hello, AWS Batch!" },

                    // 環境変数を追加または上書き
                    Environment = new List<Amazon.Batch.Model.KeyValuePair>
                    {
                        new Amazon.Batch.Model.KeyValuePair
                        {
                            Name = "ENVIRONMENT_ARGS",
                            Value = "ENVIRONMENT_VALUE"
                        }
                    },

                    // リソース要求を指定(オプション)
                    ResourceRequirements = new List<ResourceRequirement>
                    {
                        new ResourceRequirement
                        {
                            Type = ResourceType.VCPU,
                            Value = "1" // 1 vCPU
                        },
                        new ResourceRequirement
                        {
                            Type = ResourceType.MEMORY,
                            Value = "2048" // 2048 MB
                        }
                    }
                }
            };

            try
            {
                // ジョブを送信
                var submitJobResponse = await batchClient.SubmitJobAsync(submitJobRequest);

                // ジョブIDを表示
                Console.WriteLine($"Job ID: {submitJobResponse.JobId}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error submitting job: {ex.Message}");
            }
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?