Quickly Building a Backend for a Payment Management Tool from Scratch with AWS SAM

Introduction
Hello, I am Nishida, a member of the payment platform development team at KINTO Technologies.
In this article, I'd like to share how we used AWS SAM to build the backend for an internal payment operations system, which was also introduced earlier in this article.
What is AWS SAM?
First off, AWS SAM (Serverless Application Model) is a tool that makes it easy to build and deploy serverless services like Lambda and API Gateway. With AWS SAM, developers no longer need in-depth knowledge of infrastructure and can focus on building applications using a serverless architecture.
Why We Chose AWS SAM
Right after joining KINTO Technologies, I became involved in developing a payment operations system. Given the short development timeline of just 2 to 3 months, we needed to select backend technologies that supported rapid iteration Since it was an internal system with limited traffic, we decided to go with AWS SAM, leveraging my prior experience with it from a previous role.
How to Use AWS SAM
I'd like to use AWS SAM to build a REST API using API Gateway and Lambda in a serverless setup.
Here's what the directory structure looks like:
.
├── hello_world
│ ├── __init__.py
│ └── app.py
└── template.yaml
First, install AWS SAM from the official documentation.
AWS SAM uses a file called a template to manage AWS resources.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: HelloWorldFunction
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.9
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
import json
def lambda_handler(event, context):
body = {
"message": "hello world",
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
We deploy using the sam command. This time, I'll try deploying interactively using the --guided
option.
sam deploy --guided
Enter the stack name, region, etc.
Stack Name [sam-app]: # デプロイするスタック名を入力
AWS Region [ap-northeast-1]: # デプロイするリージョンを入力
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy
Confirm changes before deploy [y/N]: # 変更内容を確認するかを入力
#SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]: # SAM CLI が IAM ロールを作成するかを入力
#Preserves the state of previously provisioned resources when an operation fails
Disable rollback [y/N]: # ロールバックを無効にするかを入力
HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: # Lambda に対する認可を設定するかを入力
Save arguments to configuration file [Y/n]: # 設定を保存するかを入力
SAM configuration file [samconfig.toml]: # 設定ファイルの名前を入力
SAM configuration environment [default]: # 環境名を入力
Once the deployment is complete, check the Lambda console to confirm that HelloWorldFunction
has been created.
You can also find the endpoint by selecting the API Gateway that triggers Lambda.
Let's try sending a request using curl.
curl https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/Prod/hello
If the request is successful, you'll get a response like this:
{"message": "hello world"}
After Trying It Out
As I had prior experience with AWS SAM, I was able to get the basic infrastructure up and running in just a day, which helped us stay on track with the development schedule.
Once you're familiar with it, one of the best things about AWS SAM is how easy it makes building APIs in a serverless setup.
In addition to API Gateway and Lambda, we also use AWS SAM to build EventBridge and SQS, which are used for periodic processing such as batch processing. The official documentation has also improved a lot, which I think has lowered the barrier to getting started.
Conclusion
In this article, I shared how we quickly built the backend for a payment operations system from scratch using AWS SAM.
Since it's a tool provided by AWS, it has high compatibility, reduces the overhead of environment setup, and allows you to focus more on actual development. If you're interested, I highly recommend giving it a try.
関連記事 | Related Posts

Quickly Building a Backend for a Payment Management Tool from Scratch with AWS SAM

Lambda + TypeScript + Express.jsでAPIをサクサク開発して低コストで運用する話

AWSコストを65%削減したお話とその先に見えたこと

Develop APIs Quickly and Operate Them at Low Cost Using Lambda, TypeScript, and Express.js

Transfer Family web apps触ってみた

AWSサーバレスアーキテクチャをMonorepoツール - Nxとterraformで構築してみた!
We are hiring!
【クラウドエンジニア】Cloud Infrastructure G/東京・大阪・福岡
KINTO Tech BlogWantedlyストーリーCloud InfrastructureグループについてAWSを主としたクラウドインフラの設計、構築、運用を主に担当しています。
【クラウドプラットフォームエンジニア】プラットフォームG/東京・大阪・福岡
プラットフォームグループについてAWS を中心とするインフラ上で稼働するアプリケーション運用改善のサポートを担当しています。