6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS Lambdaで環境変数を使う(Java)

Last updated at Posted at 2016-11-20

この記事の目的

初投稿.
AWS Lambdaで環境変数が使えるようになったので,早速使ってみる.(Java)

Lambdaのコード(Java)

HelloWorld.java
public class HelloWorld {

	private static String ENV_TEST_VALUE = "ENV_TEST_VALUE";

	public static String handleRequest(String input) {
		String output;

		String envValue = System.getenv(ENV_TEST_VALUE);

		output = "Hello World : " + envValue;

		return output;
	}

}

AWS Consoleでの設定

以下の赤囲みのところで環境変数を設定できます.
Lambda_environmentValue.png

結果

テストデータを突っ込んで,"TEST"をポチッと押す.

"Hello World : TEST"

バッチリ取得できてますね.
AWS Consoleで環境変数の値を変更すれば,もちろん出力も変わります.

さいごに

これで開発用と本番用の関数を実現するための方法が楽ちんになりますね.
環境変数の制約などは,Developers.IOさんのブログが詳しく書いてます.

参考

New for AWS Lambda – Environment Variables and Serverless Application Model (SAM) | AWS Blog
【アップデート】AWS Lambdaで環境変数を使えるようになりました!!! | Developers.IO

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?