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?

9日目:AWS無料枠使い倒し「無料枠で試すLambda入門」

Posted at

無料枠で試すLambda入門:サーバーレスの第一歩

予定コスト: $0.00(無料枠内)


✅ この記事でやること

最小のNode.js関数作成、実行ロール、Invokeテストまで。


✅ 前提(準備)

CLI/zipコマンド、適切なIAM権限。


コード作成とパッケージ

ハローワールド関数をzip化。

cat > index.js <<'EOF'
exports.handler = async () => ({ statusCode:200, body: 'hello' });
EOF
zip function.zip index.js

ロール作成と権限付与

基本実行ロールを付与。

aws iam create-role --role-name lambda-basic 
  --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]}'
aws iam attach-role-policy --role-name lambda-basic 
  --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
ROLE_ARN=$(aws iam get-role --role-name lambda-basic --query Role.Arn --output text)

関数作成と実行

作成→Invoke→結果確認。

aws lambda create-function --function-name hello --runtime nodejs20.x --role $ROLE_ARN --handler index.handler --zip-file fileb://function.zip
aws lambda invoke --function-name hello out.json && cat out.json

💡 豆知識 (Tips)

  • 無料枠:100万リクエスト/月・400,000GB-秒/月
  • メモリ/タイムアウトで料金が変わる

⚠️ 落とし穴

  • 不要ログの大量出力でCloudWatch費用増
  • VPC内実行時のNAT/ルート設計不足

🧾 今日のコスト

$0.00(無料枠内)


✅ まとめ

  • 本日のゴールを確認
  • 無料枠を意識して運用
  • 次回に繋がるポイントを整理

✅ 次回予告(10日目)

「CloudFormationでインフラをコード化する方法」

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?