Skip to content

Commit

Permalink
docs: layer info
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair committed Sep 3, 2024
1 parent acd0ef4 commit c83e85b
Showing 1 changed file with 134 additions and 128 deletions.
262 changes: 134 additions & 128 deletions platform/src/components/aws/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,34 +454,34 @@ export interface FunctionArgs {
logging?: Input<
| false
| {
/**
* The duration the function logs are kept in CloudWatch.
* @default `forever`
* @example
* ```js
* {
* logging: {
* retention: "1 week"
* }
* }
* ```
*/
retention?: Input<keyof typeof RETENTION>;
/**
* The [log format](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-advanced.html)
* of the Lambda function.
* @default `"text"`
* @example
* ```js
* {
* logging: {
* format: "json"
* }
* }
* ```
*/
format?: Input<"text" | "json">;
}
/**
* The duration the function logs are kept in CloudWatch.
* @default `forever`
* @example
* ```js
* {
* logging: {
* retention: "1 week"
* }
* }
* ```
*/
retention?: Input<keyof typeof RETENTION>;
/**
* The [log format](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs-advanced.html)
* of the Lambda function.
* @default `"text"`
* @example
* ```js
* {
* logging: {
* format: "json"
* }
* }
* ```
*/
format?: Input<"text" | "json">;
}
>;
/**
* The [architecture](https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html)
Expand Down Expand Up @@ -543,45 +543,45 @@ export interface FunctionArgs {
url?: Input<
| boolean
| {
/**
* The authorization used for the function URL. Supports [IAM authorization](https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html).
* @default `"none"`
* @example
* ```js
* {
* url: {
* authorization: "iam"
* }
* }
* ```
*/
authorization?: Input<"none" | "iam">;
/**
* Customize the CORS (Cross-origin resource sharing) settings for the function URL.
* @default `true`
* @example
* Disable CORS.
* ```js
* {
* url: {
* cors: false
* }
* }
* ```
* Only enable the `GET` and `POST` methods for `https://example.com`.
* ```js
* {
* url: {
* cors: {
* allowMethods: ["GET", "POST"],
* allowOrigins: ["https://example.com"]
* }
* }
* }
* ```
*/
cors?: Input<boolean | Prettify<FunctionUrlCorsArgs>>;
}
/**
* The authorization used for the function URL. Supports [IAM authorization](https://docs.aws.amazon.com/lambda/latest/dg/urls-auth.html).
* @default `"none"`
* @example
* ```js
* {
* url: {
* authorization: "iam"
* }
* }
* ```
*/
authorization?: Input<"none" | "iam">;
/**
* Customize the CORS (Cross-origin resource sharing) settings for the function URL.
* @default `true`
* @example
* Disable CORS.
* ```js
* {
* url: {
* cors: false
* }
* }
* ```
* Only enable the `GET` and `POST` methods for `https://example.com`.
* ```js
* {
* url: {
* cors: {
* allowMethods: ["GET", "POST"],
* allowOrigins: ["https://example.com"]
* }
* }
* }
* ```
*/
cors?: Input<boolean | Prettify<FunctionUrlCorsArgs>>;
}
>;
/**
* Configure how your function is bundled.
Expand Down Expand Up @@ -788,6 +788,14 @@ export interface FunctionArgs {
/**
* A list of Lambda layer ARNs to add to the function.
*
* :::note
* Layers are only added when the function is deployed.
* :::
*
* These are only added when the function is deployed. In `sst dev`, your functions are run
* locally, so the layers are not used. Instead you should use a local version of what's
* in the layer.
*
* @example
* ```js
* {
Expand Down Expand Up @@ -1125,10 +1133,10 @@ export class Function extends Component implements Link.Linkable {
: url.cors === true || url.cors === undefined
? defaultCors
: {
...defaultCors,
...url.cors,
maxAge: url.cors.maxAge && toSeconds(url.cors.maxAge),
};
...defaultCors,
...url.cors,
maxAge: url.cors.maxAge && toSeconds(url.cors.maxAge),
};

return { authorization, cors };
});
Expand Down Expand Up @@ -1224,7 +1232,7 @@ export class Function extends Component implements Link.Linkable {
if (result.type === "error") {
throw new Error(
`Failed to build function "${args.handler}": ` +
result.errors.join("\n").trim(),
result.errors.join("\n").trim(),
);
}
return result;
Expand Down Expand Up @@ -1257,12 +1265,12 @@ export class Function extends Component implements Link.Linkable {

const linkInjection = hasLinkInjections
? linkData
.map((item) => [
`process.env.SST_RESOURCE_${item.name} = ${JSON.stringify(
JSON.stringify(item.properties),
)};\n`,
])
.join("")
.map((item) => [
`process.env.SST_RESOURCE_${item.name} = ${JSON.stringify(
JSON.stringify(item.properties),
)};\n`,
])
.join("")
: "";

const parsed = path.posix.parse(handler);
Expand Down Expand Up @@ -1292,21 +1300,21 @@ export class Function extends Component implements Link.Linkable {
name: path.posix.join(handlerDir, `${newHandlerFileName}.mjs`),
content: streaming
? [
linkInjection,
`export const ${newHandlerFunction} = awslambda.streamifyResponse(async (event, responseStream, context) => {`,
...injections,
` const { ${oldHandlerFunction}: rawHandler} = await import("./${oldHandlerFileName}${newHandlerFileExt}");`,
` return rawHandler(event, responseStream, context);`,
`});`,
].join("\n")
linkInjection,
`export const ${newHandlerFunction} = awslambda.streamifyResponse(async (event, responseStream, context) => {`,
...injections,
` const { ${oldHandlerFunction}: rawHandler} = await import("./${oldHandlerFileName}${newHandlerFileExt}");`,
` return rawHandler(event, responseStream, context);`,
`});`,
].join("\n")
: [
linkInjection,
`export const ${newHandlerFunction} = async (event, context) => {`,
...injections,
` const { ${oldHandlerFunction}: rawHandler} = await import("./${oldHandlerFileName}${newHandlerFileExt}");`,
` return rawHandler(event, context);`,
`};`,
].join("\n"),
linkInjection,
`export const ${newHandlerFunction} = async (event, context) => {`,
...injections,
` const { ${oldHandlerFunction}: rawHandler} = await import("./${oldHandlerFileName}${newHandlerFileExt}");`,
` return rawHandler(event, context);`,
`};`,
].join("\n"),
},
};
},
Expand All @@ -1331,11 +1339,11 @@ export class Function extends Component implements Link.Linkable {
})),
...(dev
? [
{
actions: ["iot:*"],
resources: ["*"],
},
]
{
actions: ["iot:*"],
resources: ["*"],
},
]
: []),
],
}),
Expand All @@ -1348,29 +1356,28 @@ export class Function extends Component implements Link.Linkable {
{
assumeRolePolicy: !$dev
? iam.assumeRolePolicyForPrincipal({
Service: "lambda.amazonaws.com",
})
Service: "lambda.amazonaws.com",
})
: iam.getPolicyDocumentOutput({
statements: [
{
actions: ["sts:AssumeRole"],
principals: [
{
type: "Service",
identifiers: ["lambda.amazonaws.com"],
},
{
type: "AWS",
identifiers: [
interpolate`arn:aws:iam::${
getCallerIdentityOutput().accountId
statements: [
{
actions: ["sts:AssumeRole"],
principals: [
{
type: "Service",
identifiers: ["lambda.amazonaws.com"],
},
{
type: "AWS",
identifiers: [
interpolate`arn:aws:iam::${getCallerIdentityOutput().accountId
}:root`,
],
},
],
},
],
}).json,
],
},
],
},
],
}).json,
// if there are no statements, do not add an inline policy.
// adding an inline policy with no statements will cause an error.
inlinePolicies: policy.apply(({ statements }) =>
Expand All @@ -1379,13 +1386,13 @@ export class Function extends Component implements Link.Linkable {
managedPolicyArns: logging.apply((logging) => [
...(logging
? [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
]
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
]
: []),
...(args.vpc
? [
"arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole",
]
"arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole",
]
: []),
]),
},
Expand Down Expand Up @@ -1450,9 +1457,9 @@ export class Function extends Component implements Link.Linkable {
entry.isDir
? archive.directory(entry.from, entry.to, { date: new Date(0) })
: archive.file(entry.from, {
name: entry.to,
date: new Date(0),
});
name: entry.to,
date: new Date(0),
});
//if (mode === "start") {
// try {
// const dir = path.dirname(toPath);
Expand Down Expand Up @@ -1497,9 +1504,8 @@ export class Function extends Component implements Link.Linkable {
args.transform?.logGroup,
`${name}LogGroup`,
{
name: interpolate`/aws/lambda/${
args.name ?? physicalName(64, `${name}Function`)
}`,
name: interpolate`/aws/lambda/${args.name ?? physicalName(64, `${name}Function`)
}`,
retentionInDays: RETENTION[logging.retention],
},
{ parent },
Expand Down

0 comments on commit c83e85b

Please sign in to comment.