LoginSignup
8
4

More than 5 years have passed since last update.

C# in AWS lambda

Posted at

よっしゃC#やろうぜ

環境

Windows10
AWS-CLI設定済み(Admin権限持ってる)
Bash on Windows

インストール

nodejs
入ってる人は飛ばしてください。入ってなければ
https://nodejs.org/ja/download/package-manager/#debian-and-ubuntu-based-linux-distributions-debian-ubuntu-linux
を参考に

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs npm

dotnet-core

https://www.microsoft.com/net/core
1.0をインストールしてください。現時点では1.0用に作られているのでmigrateしてやるぜ!って方以外はとりあえず試すだけなら1.0でやったほうが早いです。

aws-lambda-dotnet

https://github.com/aws/aws-lambda-dotnet
これにの通り

npm install -g yo generator-aws-lambda-dotnet

で完了

プロジェクトの作成

適当なワークディレクトリに移動してyoコマンドを実行します

yo aws-lambda-dotnet

質問はEmpty Functionを選んでそれ以外は適当に。

restore+test+deploy+execute!

作成されたプロジェクトのsrc/Readme.mdにすべて書いていますのでこの通りに進めます。
ここからはBoWではなくコマンドプロンプトで作業しています
(dotnetコマンドをWindows版入れたのが失敗だったっぽい?Linux版ちゃんと入れればBoWでできそう)

まずはプロジェクトルートでdotnet restore

cd "EmptyFunction"
dotnet restore

ユニットテストを実行して

cd "EmptyFunction/test/EmptyFunction.Tests"
dotnet test

問題なければデプロイ!
最初このテストがdotnet core 1.1を使っていたのでエラーが出てmigrateとかしてました。1.0入れたほうが早いです。

cd "EmptyFunction/src/EmptyFunction"
dotnet lambda deploy-function

デプロイが成功したらlambdaのマネジメントコンソールから当該ファンクションを選択して[Test]

"hogehoge"

というJSONデータを渡して結果がHOGEHOGEと帰ってくるはず!やったぜ!

CsharpLambda.PNG

8
4
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
8
4