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?

More than 1 year has passed since last update.

AWS Lambdaに Funtion URLsを設定する

Posted at

AppSyncから、cloudsearchを叩きたかったので、Lambdaに Funtion URLsを設定して、httpリゾルバで取得する形に。Lambdaリゾルバよりテストなどがしやすそうだったので。

ローカルでcloudsearchのLambda作成する形は以下。
https://qiita.com/rei-ta/items/e86546130d157561ba8e

image.png

configurationから、Function URL (Lambda Function作成後の設定も可能)

image.png

アクセス制御の方法を変えられるので可用性が高そう。
AWS資産から、使用する場合は、AWS IAMで。ローカルから暫定的に試す場合は、NONEで認証せずに使用可。試していませんが、CORSでの設定も可能とのこと。

http経由で実行すると、クエリストリングなのでパラメータ取得方法は、queryStringParametersから取得

https://xkdmddddddddddddddXjck.lambda-url.ap-northeast-1.on.aws/?q=%E3%82%A6%E3%82%AF%E3%83%A9%E3%82%A4%E3%83%8A
export const lambdaHandler = async (event, context) => {
  console.log(event.queryStringParameters);

eventのオブジェクトは以下のような構造

2022-08-28T01:38:05.969Z	e52d0a8e-3720-4e8f-9a17-a694d33107a2	INFO	{
  version: '2.0',
  routeKey: '$default',
  rawPath: '/favicon.ico',
  rawQueryString: '',
  headers: {
    'sec-fetch-mode': 'no-cors',
    referer: 'https://xkdmddddddddddddddXjck.lambda-url.ap-northeast-1.on.aws/?q=%E3%82%A6%E3%82%AF%E3%83%A9%E3%82%A4%E3%83%8A',
    'x-amzn-tls-version': 'TLSv1.2',
    'sec-fetch-site': 'same-origin',
    'accept-language': 'ja-JP,ja;q=0.9,en-US;q=0.8,en;q=0.7',
    'x-forwarded-proto': 'https',
    'x-forwarded-port': '443',
    'x-forwarded-for': '150.249.205.131',
    accept: 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
    'x-amzn-tls-cipher-suite': 'ECDHE-RSA-AES128-GCM-SHA256',
    'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
    'sec-ch-ua-mobile': '?0',
    'x-amzn-trace-id': 'Root=1-630ac6fd-47285d7b5f1cb6161c6d5e49',
    'sec-ch-ua-platform': '"Windows"',
    host: 'xkdml4bwlylraovesek6nvsxnu0urjck.lambda-url.ap-northeast-1.on.aws',
    'accept-encoding': 'gzip, deflate, br',
    'sec-fetch-dest': 'image',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
  },
  requestContext: {
    accountId: 'anonymous',
    apiId: 'xkdmddddddddddddddXjck',
    domainName: 'xkdmddddddddddddddXjck.lambda-url.ap-northeast-1.on.aws',
    domainPrefix: 'xkdmddddddddddddddXjck',
    http: {
      method: 'GET',
      path: '/favicon.ico',
      protocol: 'HTTP/1.1',
      sourceIp: '150.249.205.131',
      userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
    },
    requestId: 'e52d0a8e-3720-4e8f-9a17-a694d33107a2',
    routeKey: '$default',
    stage: '$default',
    time: '28/Aug/2022:01:38:05 +0000',
    timeEpoch: 1661650685806
  },
  isBase64Encoded: false
}
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?