Documentation
¶
Index ¶
- Constants
- func AssetCodeGo(compiler Compiler) awslambda.Code
- func NewContainerGo(scope constructs.Construct, id *string, spec *ContainerGoProps) awslambda.Function
- func NewFunction(scope constructs.Construct, id *string, spec FunctionProps) awslambda.Function
- func NewFunctionGo(scope constructs.Construct, id *string, spec *FunctionGoProps) awslambda.Function
- func SetDefaults(scope constructs.Construct, defaults *Defaults)
- type AccessLog
- type Alias
- type AliasProps
- type AuthorizerBasic
- type AuthorizerIAM
- type AuthorizerJwt
- type AuthorizerLambda
- type AuthorizerLambdaProps
- type AuthorizerPublic
- type Compiler
- type ContainerGoProps
- type Cors
- type Defaults
- type FunctionGoProps
- type FunctionProps
- type Gateway
- func (gw *Gateway) ApiId() *string
- func (gw *Gateway) CfnStage() apigw2.CfnStage
- func (gw *Gateway) NewAuthorizerBasic(access, secret string, source ...string) *AuthorizerBasic
- func (gw *Gateway) NewAuthorizerCognito(cognitoArn string, clients ...string) *AuthorizerJwt
- func (gw *Gateway) NewAuthorizerIAM() *AuthorizerIAM
- func (gw *Gateway) NewAuthorizerJwt(iss string, aud ...string) *AuthorizerJwt
- func (gw *Gateway) NewAuthorizerLambda(handler awslambda.IFunction, props *AuthorizerLambdaProps) *AuthorizerLambda
- func (gw *Gateway) NewAuthorizerPublic() *AuthorizerPublic
- type GatewayProps
- type GoCompiler
- type Hasher
- type RouteProps
- type Throttle
- type Toolchain
Constants ¶
const DefaultAccessLogFormat = `` /* 483-byte string literal not displayed */
DefaultAccessLogFormat is the JSON access log format used by default.
Variables ¶
This section is empty.
Functions ¶
func AssetCodeGo ¶
AssetCodeGo bundles lambda function from source code
func NewContainerGo ¶ added in v0.8.4
func NewContainerGo(scope constructs.Construct, id *string, spec *ContainerGoProps) awslambda.Function
func NewFunction ¶ added in v0.10.1
func NewFunction(scope constructs.Construct, id *string, spec FunctionProps) awslambda.Function
func NewFunctionGo ¶
func NewFunctionGo(scope constructs.Construct, id *string, spec *FunctionGoProps) awslambda.Function
NewFunctionGo creates Golang Lambda Function from "inline" code
func SetDefaults ¶ added in v0.14.0
func SetDefaults(scope constructs.Construct, defaults *Defaults)
SetDefaults defines defaults of functions created within the scope (stack or any construct) and its descendants. The defaults set on the nearest ancestor apply. The function can be called once per scope.
Types ¶
type AccessLog ¶ added in v0.14.0
type AccessLog struct {
// Log group to write access logs, created if not defined.
// The retention of created log group follows scud.Defaults.
LogGroup awslogs.ILogGroup
// Log format, default is DefaultAccessLogFormat.
Format *string
}
Access logging of the API
type Alias ¶ added in v0.14.0
type Alias struct {
constructs.Construct
Domain apigw2.DomainName
Mapping apigw2.ApiMapping
Record awsroute53.ARecord
}
Alias is a stable custom domain name mapped to HTTP API.
A version of API is an immutable deployment with its own host (e.g. v1.api.example.com). The alias (e.g. api.example.com) follows the live version. API Gateway custom domain answers only to its own name, so the alias is a custom domain of its own with an API mapping to the version's API. Deploy the alias by a stack that outlives versions, switching the version updates the API mapping in place.
func NewAlias ¶ added in v0.14.0
func NewAlias(scope constructs.Construct, id *string, props *AliasProps) *Alias
type AliasProps ¶ added in v0.14.0
type AliasProps struct {
// Custom domain name of the alias (e.g. api.example.com)
Host *string
// Hosted zone (domain name) where the record is created.
// Default is Host, the record is created at the zone apex.
Zone *string
// ARN of the certificate for the custom domain name.
TlsArn *string
// HTTP API the alias is mapped to. Use either Api, ApiId or ApiIdParameter.
Api apigw2.IHttpApi
// Id of HTTP API the alias is mapped to (e.g. stack output of the version).
ApiId *string
// Name of SSM parameter holding id of HTTP API the alias is mapped to
// (see GatewayProps.ApiIdParameter).
ApiIdParameter *string
// Stage of the API, default is $default.
Stage *string
}
AliasProps defines a stable custom domain mapped to a (versioned) HTTP API deployed by another stack.
type AuthorizerBasic ¶ added in v0.11.3
func (*AuthorizerBasic) AddResource ¶ added in v0.11.3
func (api *AuthorizerBasic) AddResource( endpoint string, handler awslambda.Function, ) *AuthorizerBasic
Associate a Lambda function with a REST API path. It uses the specified path as a prefix, enabling the association of the Lambda function with all subpaths under that prefix.
func (*AuthorizerBasic) AddRoute ¶ added in v0.14.0
func (api *AuthorizerBasic) AddRoute(path string, props *RouteProps) *AuthorizerBasic
Associate a Lambda function with the exact route path (see RouteProps).
type AuthorizerIAM ¶ added in v0.8.0
type AuthorizerIAM struct {
constructs.Construct
RestAPI apigw2.HttpApi
// contains filtered or unexported fields
}
func (*AuthorizerIAM) AddResource ¶ added in v0.8.0
func (api *AuthorizerIAM) AddResource( endpoint string, handler awslambda.Function, grantee awsiam.IGrantable, ) *AuthorizerIAM
Associate a Lambda function with a REST API path. It uses the specified path as a prefix, enabling the association of the Lambda function with all subpaths under that prefix.
Protect access to resource only for AWS IAM principals.
func (*AuthorizerIAM) AddRoute ¶ added in v0.14.0
func (api *AuthorizerIAM) AddRoute(path string, props *RouteProps) *AuthorizerIAM
Associate a Lambda function with the exact route path (see RouteProps). RouteProps.Grantee is granted to invoke the route.
type AuthorizerJwt ¶ added in v0.8.0
type AuthorizerJwt struct {
constructs.Construct
RestAPI apigw2.HttpApi
// contains filtered or unexported fields
}
func (*AuthorizerJwt) AddResource ¶ added in v0.8.0
func (api *AuthorizerJwt) AddResource( endpoint string, handler awslambda.Function, accessScope ...string, ) *AuthorizerJwt
Associate a Lambda function with a REST API path. It uses the specified path as a prefix, enabling the association of the Lambda function with all subpaths under that prefix.
Protect access to resource only for principals with valid JWT token.
func (*AuthorizerJwt) AddRoute ¶ added in v0.14.0
func (api *AuthorizerJwt) AddRoute(path string, props *RouteProps) *AuthorizerJwt
Associate a Lambda function with the exact route path (see RouteProps). RouteProps.AuthorizationScopes are required from the token.
type AuthorizerLambda ¶ added in v0.14.0
func (*AuthorizerLambda) AddResource ¶ added in v0.14.0
func (api *AuthorizerLambda) AddResource( endpoint string, handler awslambda.Function, ) *AuthorizerLambda
Associate a Lambda function with a REST API path. It uses the specified path as a prefix, enabling the association of the Lambda function with all subpaths under that prefix.
func (*AuthorizerLambda) AddRoute ¶ added in v0.14.0
func (api *AuthorizerLambda) AddRoute(path string, props *RouteProps) *AuthorizerLambda
Associate a Lambda function with the exact route path (see RouteProps).
type AuthorizerLambdaProps ¶ added in v0.14.0
type AuthorizerLambdaProps struct {
// Construct id of the authorizer, it is also the default name of
// the authorizer. Default is derived from the function's construct id.
Id string
// Name of the authorizer, default is Id.
AuthorizerName *string
// Identity sources (e.g. "$request.header.Authorization").
// Empty (default) means no identity source: API Gateway invokes
// the authorizer for every request, including anonymous ones.
// API Gateway requires disabled caching (zero ResultsCacheTtl)
// for authorizers without identity source.
IdentitySource []string
// Response types of the authorizer, default is SIMPLE.
// SIMPLE responses use authorizer payload format 2.0, IAM uses 1.0.
ResponseTypes []authorizers.HttpLambdaResponseType
// How long API Gateway caches authorizer results, default 0 (disabled).
ResultsCacheTtl awscdk.Duration
}
Properties of Lambda authorizer
type AuthorizerPublic ¶ added in v0.11.3
func (*AuthorizerPublic) AddResource ¶ added in v0.11.3
func (api *AuthorizerPublic) AddResource( endpoint string, handler awslambda.Function, ) *AuthorizerPublic
Associate a Lambda function with a REST API path. It uses the specified path as a prefix, enabling the association of the Lambda function with all subpaths under that prefix.
func (*AuthorizerPublic) AddRoute ¶ added in v0.14.0
func (api *AuthorizerPublic) AddRoute(path string, props *RouteProps) *AuthorizerPublic
Associate a Lambda function with the exact route path (see RouteProps). The route is public even if the HTTP API has default authorizer.
type Compiler ¶ added in v0.6.0
type Compiler interface {
awscdk.ILocalBundling
SourceCodeModule() string
SourceCodeLambda() string
SourceCodeVersion() string
}
type ContainerGoProps ¶ added in v0.8.4
type ContainerGoProps struct {
*awslambda.DockerImageFunctionProps
// Canonical name of Golang module that containing the function
// SourceCodeModule: "github.com/fogfish/scud",
SourceCodeModule string
// Path to lambda function relative to the module
// SourceCodeLambda: "test/lambda/go"
SourceCodeLambda string
// The version of software asset passed as linker flag
// -ldflags '-X main.version=...'
SourceCodeVersion string
// Toolchain configuration for building Go Lambda function
Toolchain *Toolchain
// Path to Dockerfile relative to the module,
// if not specified, the default Dockerfile will be generated.
//
// The file must contain:
// ADD bootstrap /bin/bootstrap
// CMD ["/bin/bootstrap"]
Dockerfile string
// Static files included into container, the path is relative to module
// Only added to container if Dockerfile is not specified, otherwise it's caller responsibility to add them into container within Dockerfile
StaticAssets []string
// Linux Alpine Packages (apk) to be installed within the container
// Only added to container if Dockerfile is not specified, otherwise it's caller responsibility to add them into container within Dockerfile
Packages []string
}
func (*ContainerGoProps) HKT1 ¶ added in v0.10.7
func (*ContainerGoProps) HKT1(awslambda.Function)
func (*ContainerGoProps) UniqueID ¶ added in v0.10.4
func (props *ContainerGoProps) UniqueID() string
type Cors ¶ added in v0.14.0
type Cors struct {
// Origins allowed to access the API
AllowOrigins []string
// Headers allowed in the request, default is Authorization, Content-Type
AllowHeaders []string
// Headers exposed to browser in the response
ExposeHeaders []string
// Allow credentials (cookies, authorization headers) in cross-origin requests
AllowCredentials bool
// For how long browser caches the preflight response, default is 10 minutes
MaxAge awscdk.Duration
}
CORS configuration of the HTTP API
type Defaults ¶ added in v0.14.0
type Defaults struct {
// Function timeout, the library's default is 1 minute.
Timeout awscdk.Duration
// Function memory size (MB), the AWS Lambda's default is 128 MB.
MemorySize *float64
// Log group shared by all functions in the scope.
// When defined, per-function log groups are not created.
LogGroup awslogs.ILogGroup
// Prefix of per-function log group names, e.g. "/myapp/mystack".
// The log group is named <prefix>/<function name>.
// The library's default is the function name.
LogGroupPrefix string
// Retention of per-function log groups, the library's default is 5 days.
LogRetention awslogs.RetentionDays
// Removal policy of per-function log groups, the library's default is DESTROY.
LogRemovalPolicy awscdk.RemovalPolicy
}
Defaults of functions (and log groups) created by the library within a scope. Properties given explicitly to the function take precedence.
Functions behind API Gateway HTTP API must have the timeout shorter than the integration timeout (30 seconds by default, maximum).
type FunctionGoProps ¶
type FunctionGoProps struct {
*awslambda.FunctionProps
// Canonical name of Golang module that containing the function
// SourceCodeModule: "github.com/fogfish/scud",
SourceCodeModule string
// Path to lambda function relative to the module
// SourceCodeLambda: "test/lambda/go"
SourceCodeLambda string
// The version of software asset passed as linker flag
// -ldflags '-X main.version=...'
SourceCodeVersion string
// Toolchain configuration for building Go Lambda function
Toolchain *Toolchain
}
FunctionGoProps is properties of the function
func (*FunctionGoProps) HKT1 ¶ added in v0.10.7
func (*FunctionGoProps) HKT1(awslambda.Function)
func (*FunctionGoProps) UniqueID ¶ added in v0.10.4
func (props *FunctionGoProps) UniqueID() string
type FunctionProps ¶ added in v0.10.1
type Gateway ¶
type Gateway struct {
constructs.Construct
RestAPI apigw2.HttpApi
// Custom domain name, nil if not configured
Domain apigw2.DomainName
// DNS record of the custom domain name, nil if not configured
Record awsroute53.ARecord
// contains filtered or unexported fields
}
func NewGateway ¶
func NewGateway(scope constructs.Construct, id *string, props *GatewayProps) *Gateway
NewGateway creates new instance of Gateway
func (*Gateway) CfnStage ¶ added in v0.14.0
L1 construct of the default stage, use it to configure stage settings not covered by the library.
func (*Gateway) NewAuthorizerBasic ¶ added in v0.11.3
func (gw *Gateway) NewAuthorizerBasic(access, secret string, source ...string) *AuthorizerBasic
Creates integration with Basic Authorizer to authorize incoming requests. This integration implements a simple access/secret key validation mechanism, allowing you to protect your API endpoints using basic authentication. By validating the provided credentials against the configured access and secret keys, the library ensures that only authorized clients can access your resources, enhancing the security of your API.
func (*Gateway) NewAuthorizerCognito ¶ added in v0.8.0
func (gw *Gateway) NewAuthorizerCognito(cognitoArn string, clients ...string) *AuthorizerJwt
Creates integration with AWS Cognito to authorize incoming requests. This integration allows you to manage user authentication and authorization seamlessly. By utilizing AWS Cognito, you can implement robust user sign-up, sign-in, and access control mechanisms. The library ensures that only authenticated users with valid tokens can access your API endpoints, providing an additional layer of security and user management capabilities.
func (*Gateway) NewAuthorizerIAM ¶ added in v0.8.0
func (gw *Gateway) NewAuthorizerIAM() *AuthorizerIAM
Creates integration with AWS IAM to authorize incoming requests. This integration ensures that only authenticated and authorized principals can access the resources and functionalities provided by your Lambda functions. By leveraging AWS IAM policies and roles, the library enforces fine-grained access control, enhancing the security of your API endpoints.
func (*Gateway) NewAuthorizerJwt ¶ added in v0.8.0
func (gw *Gateway) NewAuthorizerJwt(iss string, aud ...string) *AuthorizerJwt
Creates integration with Single Sign On provider (e.g. Auth0) to authorize incoming requests using JWT tokens. This integration allows you to leverage external identity providers for user authentication, ensuring secure and seamless access to your API endpoints. By validating JWT tokens issued by the SSO provider, the library ensures that only authenticated users can access your resources. Additionally, this setup can support various SSO standards and providers, enhancing flexibility and security in managing user identities and permissions.
func (*Gateway) NewAuthorizerLambda ¶ added in v0.14.0
func (gw *Gateway) NewAuthorizerLambda(handler awslambda.IFunction, props *AuthorizerLambdaProps) *AuthorizerLambda
Creates integration with own Lambda (REQUEST) authorizer. Use package github.com/fogfish/scud/authorizer to implement the function.
func (*Gateway) NewAuthorizerPublic ¶ added in v0.11.3
func (gw *Gateway) NewAuthorizerPublic() *AuthorizerPublic
Creates public (unprotected) integration to authorize incoming requests. This integration allows unrestricted access to the associated API endpoints, enabling any client to interact with the resources and functionalities provided by your Lambda functions without requiring authentication or authorization. It is suitable for scenarios where open access is desired, such as public APIs or endpoints that do not handle sensitive data.
type GatewayProps ¶ added in v0.7.0
type GatewayProps struct {
*apigw2.HttpApiProps
// Custom domain name of the API (e.g. v1.api.example.com), requires TlsArn.
Host *string
// ARN of the certificate for the custom domain name.
TlsArn *string
// Hosted zone (domain name) where the custom domain record is created.
// Default is the Host without its first label
// (e.g. api.example.com for v1.api.example.com).
Zone *string
// Shortcut to enable CORS for the given origin with default headers.
// Use Cors for full control.
AllowOrigins *string
// CORS configuration, ignored if HttpApiProps.CorsPreflight is defined.
Cors *Cors
// Access logging of the default stage
AccessLog *AccessLog
// Throttling of the default stage (all routes). Route specific throttling
// is defined by RouteProps.Throttle.
Throttle *Throttle
// Name of SSM parameter, the API id is exported to (e.g. /myapp/v1/api).
// Use it to refer the versioned API from another stack (see NewAlias).
ApiIdParameter *string
}
type GoCompiler ¶ added in v0.6.0
type GoCompiler struct {
// contains filtered or unexported fields
}
func NewGoCompiler ¶ added in v0.6.0
func NewGoCompiler( sourceCodePackage string, sourceCodeLambda string, sourceCodeVersion string, config *Toolchain, ) *GoCompiler
func (*GoCompiler) SourceCodeLambda ¶ added in v0.6.0
func (g *GoCompiler) SourceCodeLambda() string
func (*GoCompiler) SourceCodeModule ¶ added in v0.8.3
func (g *GoCompiler) SourceCodeModule() string
func (*GoCompiler) SourceCodeVersion ¶ added in v0.8.3
func (g *GoCompiler) SourceCodeVersion() string
func (*GoCompiler) TryBundle ¶ added in v0.6.0
func (g *GoCompiler) TryBundle(outputDir *string, options *awscdk.BundlingOptions) *bool
type Hasher ¶ added in v0.10.6
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a utility to compute hash of lambda function and its dependencies.
The hash covers:
- the content of every source file (Go, Cgo, assembly, embedded files) of every package the function depends on that belongs to the main module or to a module replaced by a local directory;
- the path and version of every other module the function depends on;
- the Go toolchain version;
- the build configuration (GOOS, GOARCH, CGO_ENABLED, ldflags, etc).
Packages are resolved by `go list` in module mode, file names are hashed relative to the package import path, so the hash is the same on any machine regardless of the checkout location.
type RouteProps ¶ added in v0.14.0
type RouteProps struct {
// Function handling requests of the route (required)
Handler awslambda.IFunction
// HTTP methods of the route. The default is every method except OPTIONS
// if CORS is enabled at the gateway (preflight is answered by
// API Gateway), otherwise ANY.
Methods []apigw2.HttpMethod
// Construct id of the route. If the route has multiple methods, the id is
// suffixed with the method. The default is derived from the method and
// the whole path (e.g. GET/{instance}/facts), as HttpApi.AddRoutes does.
Id string
// Payload format of the Lambda integration, default is 1.0.
//
// - 1.0: the function receives events.APIGatewayProxyRequest, the context
// of Lambda authorizer is at RequestContext.Authorizer
// - 2.0: the function receives events.APIGatewayV2HTTPRequest, the context
// of Lambda authorizer is at RequestContext.Authorizer.Lambda
//
// One integration per function and payload format is shared by all routes.
PayloadFormatVersion apigw2.PayloadFormatVersion
// Throttling of the route, overrides the gateway's throttling.
Throttle *Throttle
// OAuth scopes required by the route (JWT and Cognito authorizers only).
AuthorizationScopes []string
// Principal granted to invoke the route (IAM authorizer only).
Grantee awsiam.IGrantable
}
RouteProps defines the exact route of HTTP API.
Unlike AddResource, the route matches the path exactly. The path may contain path parameters (e.g. /{instance}/facts), greedy path parameter (e.g. /files/{proxy+}) or be the root "/".
type Throttle ¶ added in v0.14.0
type Throttle struct {
// The steady-state rate limit (requests per second).
RateLimit float64
// The maximum number of concurrent requests.
BurstLimit float64
}
Throttling of the API
type Toolchain ¶ added in v0.12.1
type Toolchain struct {
// Go environment, default includes
// GOOS=linux
// GOARCH=arm64
// CGO_ENABLED=0
//
// The compiler inherits the environment of the process (HOME, GOPATH,
// GOCACHE, GOPROXY, GOPRIVATE, GOFLAGS, etc), variables defined here
// override inherited ones.
GoEnv map[string]string
// Linker flags passed to the Go linker (-ldflags).
LDFlags []string
// Go variables injected at link time using -X key=value.
// Example: -ldflags "-X main.version=1.0.0"
LDVars map[string]string
}
Configure Go compiler and Linter
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01_simple_function
command
|
|
|
01_simple_function/lambda
command
|
|
|
02_api_with_auth
command
|
|
|
internal
|
|
|
cmd/auth
command
|
|
|
test
|
|
|
lambda/another
command
|
|
|
lambda/go
command
|