---
# System prepended metadata

title: '`sam local start-api`'
tags: [sam]

---

# `sam local start-api`

[TOC]

###### tags: `sam`

---

## Prepare container

### Create `.env` file

```properties
POSTGRES_PASSWORD=secret
```

### Create a docker network

```shell
% docker network create sam-local-network
```

### Create and run a new container from image `postgres`

```shell
% docker run \
-d \
--env-file .env \
-h sam-local-postgres \
--name sam-local-postgres \
--network sam-local-network \
-p 5432:5432 \
postgres
```

## Run locally

### Create `.env` file

```json
{
	"Parameters": {
		"DATASOURCE_CATALOG": "postgres",
		"DATASOURCE_HOST": "postgres",
		"DATASOURCE_LOGIN": "postgres",
		"DATASOURCE_PORT": "5432",
		"DATASOURCE_SHADOW": "secret",
		"LOG_LEVEL": "debug",
		"SPRING_OUTPUT_ANSI_ENABLED": "always",
		"SPRING_PROFILES_ACTIVE": "dev"
	}
}
```

### Build

```shell
% sam build
```

### Invoke Lambda function

```shell
% sam local start-api \
-n env.json \
--docker-network sam-local-network \
--skip-pull-image
```

## LIFF

1. liff.init()
2. liff.login()
3. liff.getAccessToken()
4. `GET https://api.line.me/oauth2/v2.1/verify?access_token`
5. `GET https://api.line.me/v2/profile`