Live Lambda Development | Serverless Stack (SST)<\/a><\/p>\nAPI\u3092\u5897\u3084\u3057\u3066\u307f\u308b<\/h2>\n
API\u3092\u5897\u3084\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n
\u4eca\u56de\u306f\u3001\/echo?name=uchiko<\/code> \u306e\u3088\u3046\u306a\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u308b\u3068 Hello, uchiko<\/code> \u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8fd4\u3063\u3066\u304f\u308bAPI\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\u307e\u305aGo\u8a00\u8a9e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n
src\/<\/code> \u4e0b\u306b echo\/<\/code> \u3068\u3044\u3046\u540d\u524d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n\u305d\u3057\u3066\u3001\u305d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b main.go<\/code> \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\npackage main\n\nimport (\n "fmt"\n "github.com\/aws\/aws-lambda-go\/events"\n "github.com\/aws\/aws-lambda-go\/lambda"\n)\n\nfunc Handler(request events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) {\n return events.APIGatewayProxyResponse{\n Body: fmt.Sprintf("Hello, %s", request.QueryStringParameters["name"]),\n StatusCode: 200,\n }, nil\n}\n\nfunc main() {\n lambda.Start(Handler)\n}<\/code><\/pre>\n\u30ea\u30af\u30a8\u30b9\u30c8\u304b\u3089 name<\/code> \u306b\u8a2d\u5b9a\u3055\u308c\u305f\u5024\u3092\u62bd\u51fa\u3057\u3066\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u306b\u57cb\u3081\u8fbc\u3080\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\nstacks\/MyStack.js<\/code> \u3067\u306f\u3001 \/echo<\/code> \u3068\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u95a2\u9023\u4ed8\u3051\u307e\u3059\u3002<\/p>\nconst api = new sst.Api(this, "Api", {\n routes: {\n "GET \/": "src",\n "GET \/echo": "src\/echo", \/\/ \u8ffd\u8a18\n } \n})<\/code><\/pre>\n\u4ee5\u4e0a\u3067\u3001\u5b8c\u4e86\u3067\u3059\u3002\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u3066\u3001\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n
\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u4f5c\u6210\u3057\u3066\u307f\u308b<\/h2>\n
Next.js\u3067\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3092\u4f5c\u6210\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n
\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u7528\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n
$ npx create-next-app frontend<\/code><\/pre>\n\u6b21\u306b\u3001SST\u3068Next\u9593\u3067\u74b0\u5883\u5909\u6570\u3092\u5171\u6709\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u3068\u306a\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n
$ cd frontend\/\n$ npm install @serverless-stack\/static-site-env --save-dev<\/code><\/pre>\nfrontend\/package.json<\/code> \u306e scripts.dev<\/code> \u3092\u4ee5\u4e0b\u306e\u5185\u5bb9\u306b\u66f8\u304d\u63db\u3048\u3066\u304a\u304d\u307e\u3059\u3002<\/code><\/p>\n"dev": "sst-env -- next dev"<\/code><\/pre>\nfrontend\/pages\/api\/hello.js<\/code> \u3092\u4ee5\u4e0b\u306e\u5185\u5bb9\u306b\u66f8\u304d\u63db\u3048\u3066\u3001API\u30ea\u30af\u30a8\u30b9\u30c8\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n\/\/ Next.js API route support: https:\/\/nextjs.org\/docs\/api-routes\/introduction\n\nconst apiEndpoint = process.env.API_ENDPOINT;\n\nexport default async function handler(req, res) {\n const name = req.query.name;\n const response = await fetch(`${apiEndpoint}\/echo?name=${name}`);\n res.status(200).send(await response.text());\n}<\/code><\/pre>\nfrontend\/pages\/index.js<\/code> \u3092\u4ee5\u4e0b\u306e\u5185\u5bb9\u306b\u66f8\u304d\u63db\u3048\u3066\u3001UI\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\nimport { useState } from 'react';\n\nexport default function App() {\n const [msg, setMsg] = useState(null);\n const [name, setName] = useState('');\n\n const onClick = async () => {\n const res = await fetch(`\/api\/hello?name=${name}`);\n setMsg(await res.text());\n }\n\n const onChangeName = (event) => {\n setName(event.target.value);\n };\n\n return (\n <div className="App">\n <input type="text" value={name} onChange={onChangeName}\/>\n <button onClick={onClick}>Click Me!<\/button>\n {msg && <div>{msg}<\/div>}\n <\/div>\n )\n}<\/code><\/pre>\nstacks\/MyStack.js<\/code> \u3067\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u7528\u306e\u8a2d\u5b9a\u3092\u8ffd\u8a18\u3057\u307e\u3059\u3002<\/p>\nconst site = new sst.NextjsSite(this, "Site", {\n path: 'frontend',\n environment: {\n REGION: scope.region,\n API_ENDPOINT: api.url,\n },\n});\n\nsite.attachPermissions([api]);\n\nthis.addOutputs({\n URL: site.url,\n});<\/code><\/pre>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3001\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u5074\u3092\u30c7\u30d7\u30ed\u30a4\u3057\u307e\u3059\u3002<\/p>\n
$ npx sst start<\/code><\/pre>\n\u307e\u305f\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u5074\u3067\u3082\u3001\u958b\u767a\u7528\u306e\u30b5\u30fc\u30d0\u3092\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n
$ cd frontend\/\n$ npm run dev<\/code><\/pre>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3001\u52d5\u4f5c\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n
<\/p>\n
\u611f\u60f3<\/h2>\n
\u3053\u3053\u307e\u3067\u3067\u3001\u9a5a\u304f\u307b\u3069\u304b\u3093\u305f\u3093\u306b\u30b5\u30fc\u30d0\u30ec\u30b9\u958b\u767a\u304c\u3067\u304d\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n
\u73fe\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f\u3001Serverless Framework\u3092\u4f7f\u3063\u3066\u304a\u308a\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u3088\u3046\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4e00\u751f\u61f8\u547d\u66f8\u3044\u3066\u3044\u307e\u3057\u305f\u3002\u305d\u308c\u3068\u6bd4\u3079\u308b\u3068SST\u306e\u958b\u767a\u4f53\u9a13\u306f\u3068\u3066\u3082\u826f\u3044\u5370\u8c61\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
Serverless Stack | Serverless Stack (SST) Serverless Stack(SST)\u3068\u306f\u3001\u30b5\u30fc\u30d0\u30ec\u30b9\u30a2\u30d7\u30ea\u3092\u7c21\u5358\u306b\u69cb\u7bc9\u3059\u308b\u305f\u3081\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3067\u3059\u3002JavaScript\/TypeScript,Python,Golang\u306a\u3069\u306e\u8a00\u8a9e\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u307e\u3059\u3002 \u307e\u3060\u3001\u3042\u307e\u308a\u6709\u540d\u3067\u306f\u306a\u3044\u5370\u8c61\u3067\u3059\u304c\u3001Github\u306e\u30b9\u30bf\u30fc\u6570\u3084\u4ee5\u4e0b\u306e\u30cb\u30e5\u30fc\u30b9\u306a\u3069\u304c\u3042\u308a\u3001\u671f\u5f85\u5024\u304c\u9ad8\u3044\u3067\u3059\u3002 Se […]<\/p>\n","protected":false},"author":5,"featured_media":1995,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[344,128,78],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/1990"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=1990"}],"version-history":[{"count":3,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/1990\/revisions"}],"predecessor-version":[{"id":1996,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/1990\/revisions\/1996"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/1995"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=1990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=1990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=1990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}