Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { AssumeRoleCommand } from "@aws-sdk/client-sts";
2import { EVER_BUCKET } from "@hey/data/constants";
3import { Status } from "@hey/data/enums";
4import type { Context } from "hono";
5import handleApiError from "@/utils/handleApiError";
6import stsClient from "@/utils/stsClient";
7
8const params = {
9 DurationSeconds: 900,
10 Policy: `{
11 "Version": "2012-10-17",
12 "Statement": [
13 {
14 "Effect": "Allow",
15 "Action": [
16 "s3:PutObject",
17 "s3:GetObject",
18 "s3:AbortMultipartUpload"
19 ],
20 "Resource": [
21 "arn:aws:s3:::${EVER_BUCKET}/*"
22 ]
23 }
24 ]
25 }`
26};
27
28const getSTS = async (ctx: Context) => {
29 try {
30 const command = new AssumeRoleCommand({
31 ...params,
32 RoleArn: undefined,
33 RoleSessionName: undefined
34 });
35 const { Credentials: credentials } = await stsClient.send(command);
36
37 return ctx.json({
38 data: {
39 accessKeyId: credentials?.AccessKeyId,
40 secretAccessKey: credentials?.SecretAccessKey,
41 sessionToken: credentials?.SessionToken
42 },
43 status: Status.Success
44 });
45 } catch (error) {
46 return handleApiError(ctx, error);
47 }
48};
49
50export default getSTS;