1.153.1 • Published 2 years ago

@makemydeal/cdk-lambda-stack v1.153.1

Weekly downloads
3,339
License
ISC
Repository
-
Last release
2 years ago

@makemydeal/cdk-lambda-stack

This package contains stacks for creating lambdas. These stacks take in as configuration the location of the build artifacts for the lambda, the name of the lambda, etc. The stacks give you the following options:

Stacks

StackDescription
LambdaStackCreate Lambdas without hooks to RestAPI, SNS or anything else. This is the base stack for the other implementations
RestApiLambdaStackCreate Lambdas and associate them with APIGateway for RestAPI calls. You have the option to pass in an already configured Custom Domain to associate API Gateway with
SnsLambdaStackCreate or use an existing SNS Topic and create lambdas as subscribers to that topic.
SqsLambdaStackCreate or use an existing SQS Queue and create lambdas as event sources for the queue.

NOTE RestApiLambdaStack, SnsLambdaStack and SqsLambdaStack all extend LambdaStack.

LambdaStack Properties

A LambdaStack will add Lambdas to your environment. It will not associate them to RestAPI, SNS or anything else. This stack is the base for the other stacks, and can even serve as the base for your own stack.

When defining a LambdaStack, you provide the following properties.
| Property | Required | Type | Description | --- | --- | --- | applicationName | Yes | string | Name of the application and used as a prefix for all lambda names | splunkForwarder | No | LambdaStackSplunkForwarderProps | If you wish to define a splunk forwarder, you can specify this object, see the definition of the object below | definition | Yes | LambdaDefinition | The definition of each lambda you wish to deploy. LambdaDefinition is well documented in the interface itself which should reflect what each property is for. | includeNewRelicExtension | No | boolean | Should the NewRelic Lambda Extension be added (default: true)

LambdaStackSplunkForwarderProps

PropertyRequiredTypeDescription
optionNoLambdaStackSplunkForwarderPropsOption to use to get the ARN for the splunk forwarder (see below). By Default, USE_DEFAULT is the option selected
valueNostringFor USE_CUSTOM_ARN or USE_PARAMETER_STORE, the value you want to specify is placed here.

LambdaStackPropsSplunkForwarderOptions

PropertyDescription
USE_DEFAULT*Use the default SplunkForwarder defined which will forward to cai-mmd* indexes
USE_CUSTOM_ARNSpecify a custom ARN for the splunk forwarder
USE_PARAMETER_STORESpecify the key for the parameter store that contains the ARN for the forwarder
NONEDo not attach a splunk forwarder

LambdaVersionDefinition

PropertyDescription
descriptionOptional Description of the version. Useful for the package.json version
removalPolicyWhat should we do with the version once CloudFormation no longer manages it? Default is to retain.

LambdaAliasDefinition

PropertyDescription
descriptionOptional Description of the alias
aliasNameName of the alias. Default is "live"
removalPolicyWhat should we do with the alias once CloudFormation no longer manages it? Default is to retain.
provisionedConcurrencyOptional definition for provisioned concurrency

LambdaProvisionedConcurrency

PropertyDescription
executionsnumber of instances to have warm
minCapacityminimum capacity when auto scaling (optional)
maxCapacitymaximum capacity when auto scaling (required)
utilizationTargetWhen to scale (0.5 means 50%)

RestApiLambdaStack Properties

RestApiLambdaStack extends LambdaStack to allow for creation of an API Gateway and adding the Lambdas as endpoints. It also allows creation of lambdas for Custom Authorizers as well. Below are the properties to pass when constructing the class. These properties are an extension of the properties defined for the LambdaStack above. This section will define the additional properties.

PropertyRequiredTypeDescription
enableCrossOriginYesbooleanShould Cross Origin support be enabled. Currently this supports only * support, and does not allow for specifying a domain. Default is false
definitionYesRestApiLambdaDefinitionDefinition of each lambda for the account. This interface is well documented in code and will define eveything you need and can do when using the interface via intellisense. The RestApiEndpoint interface will be defined below for more detail about setting up the endpoint
basePathNostringIf you are using a custom domain, you can set up a basePath which serves as a virtual folder for your API. You can use this to define the business domain that this API is serving
stageNostringThe name of the stage you wish to set up with this API. Default is api
domainNameNostringFor REGIONAL and EDGE endpoints, this is the name of the custom domain you wish to set up. This can be retrieved from SSM, imported from a stack variable on another stack or simply hard coded.
endpointTypeNoEndpointTypeThe endpoint type as defined by AWS. Default is REGIONAL. You can look uop their meaning in AWS docs on EndpointType
createSecondaryPrivateApiGatewayNobooleanWhen set, it will create a second API gateway which will be a Private API gateway using the same lambdas and same endpoint definitions.
privateEndpointNoRestApiLambdaStackPrivateEndpointPropsIf you wish to set this up as a private endpoint, and specify endpointType = PRIVATE then these are settings you also need to provide to set it up.
modelsNoRestApiModelOptionsModels used to validate the request coming in
customAuthorizersNoRestApiCustomAuthorizers[]Set of Custom Authorizers that you would like to define in this API Gateway to be used on your endpoints.
existingDefinitionNoRestApiLambdaExistingDefinition[]Set of existing lambdas you would like to add endpoints for. This means the lambda is not created in this stack, but an endpoint on api gateway is created
mockDefinitionNoRestApiMockDefinition[]Set of API Gateway Mock Endpoints you wish to create. These will respond with JSON, for example, on a certain endpoint but not be a proxy to Lambda.
httpProxyDefinitionNoRestApiHttpProxyDefinition[]Set of HTTP Proxies to add to API Gateway

MockDefinitions

MockDefinitions allow you to have API Gateway return a response to an endpoint that is static. You can supply the JSON of your choice if you wish. This can be useful for any mocking you wish to do, and the template can consiste of some variables from API Gateway. Please refer to this document about that information: https://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#mapping-response-parameters

HttpProxyDefinitions

HttpProxyDefinitions allow you to proxy requests right to other HTTP resources, bypassing the need for a lambda to call those endpoints. If your intention is to just pass requests through, this could be a cost saving alternative.

Application Version

One common use-case would be to return the version of the application. Since this is a pretty standard item, we've added a helper function to create this mock integration.

mockDefinitionCreateVersion will take in 3 parameters: | Parameter | Default | Description | --- | --- | appVersion | | The version of the application being deployed. | httpMethod | 'GET' | The Http Method / Verb to use for this mock | path | /echo | The route to use for this mock

RestApiLambdaStackPrivateEndpointProps

PropertyRequiredTypeDescription
vpcEndpointIdNostringThe VPC EndpointId you wish to use. This MUST BE concrete if it is specified. This means it cannot be read from SSM directly. Our tooling has the ability to read from SSM for each CodeBuild and passes it back to the app synthizer so you can pass a concrete value back
privateDnsEnabledNobooleanSetup Private DNS for this VPCE. There can only be one endpoint with this turned on per VPC
portNonumberDefault is 443
regionNostringRegion name, the default is the current region we are running under

RestApiModelOptions

This extends the AWS CDK ModelOptions by requiring the modelName be entered. We use the modelName later when assigning the model to the given endpoint.

RestApiCustomAuthorizers

PropertyRequiredTypeDescription
sourceTypeYesstringEXISTING_ARN to pass in an ARN or LAMBDA_DEFINITION to reference a lambda (by the name assigned in the definition array) as the authorizer
sourceValueYesstringThe ARN or Lambda Name based on your selection in sourceType
typeNostringThe type of authorizer TOKEN or REQUEST. The default is TOKEN
settingsNoRestApiCustomAuthorizersToken or RestApiCustomAuthorizersRequestThe properties needed for the given type of authorizer selected
nameYesstringThe name of the authorizer. This will be used when adding it to the API Gateway and will also be used when referencing it in the endpoint definition.
cacheTtlNoDurationHow long to cache the result. Default is Duration.minutes(5)

RestApiCustomAuthorizersToken

PropertyRequiredTypeDescription
identitySourceNostringThe identity source (where is the token). By Default, IdentitySource.headers('Authorization')
validationRegexNostringRegEx to validate the token

RestApiCustomAuthorizersRequest

PropertyRequiredTypeDescription
identitySourcesYesstring[]1 or more IdentitySources to specify the keys to cache by when caching the result

LambdaCreateAliasStack

A LambdaCreateAliasStack will add a new alias to an existing lambda function. It will find an existing alias and point the new alias to that function version. This can be useful for blue/green deployment so you can move a "live" alias to a "Dark" existing alias.

When defining a LambdaCreateAliasStack, you provide the following properties.
| Property | Required | Type | Description | --- | --- | --- | applicationName | Yes | string | Name of the application and used as a prefix for all lambda names | alias | Yes | LambdaAliasDefinition | This will define the alias you wish to create | aliasToFind | Yes | LambdaCreateAliasAliasToFindProps | The alias to find and the method on how to find it | definition | Yes | LambdaDefinition | The definition of all the lambdas you wish to add a new alias to. This leverages the same interface used to create the alias to make it easier.

Managers

Managers are used to have a consolidated object that will control the CICD and Build process. This allows the same object to be passed to the CICD and APP setups. They allow for custom actions to be run during the IAC Setup, the Environment Setup, and when creating the stack. These managers will be passed to the CICD process.

Each stack above has a corresponding manager:

  • LambdaStackManager
  • RestApiLambdaStackManager
  • SnsLambdaStackManager
  • SqsLambdaStackManager
  • LambdaCreateAliasStackManager

Usage

import { ParameterType, StringParameter } from '@aws-cdk/aws-ssm';
import { Construct } from '@aws-cdk/core';
import {
    RestApiCreateStackProps,
    RestApiLambdaStack,
    RestApiLambdaStackManager,
    RestApiLambdaStackManagerProps
} from '@makemydeal/cdk-lambda-stack';
import { isPrivateApi } from './utils';

export class DealerRestApiLambdaManager extends RestApiLambdaStackManager {
    public CreateStack(scope: Construct, props: RestApiCreateStackProps): RestApiLambdaStack {
        const stack = super.CreateStack(scope, props) as RestApiLambdaStack;

        const { environmentName } = props;

        // add storage of the restApi and stage to parameter store
        new StringParameter(stack, `${stack.instanceName}-parameter-restapiid`, {
            parameterName: `/dr/${environmentName}/services/dealer/lambda/restApiId`,
            stringValue: stack.ApiGateway.restApiId,
            type: ParameterType.STRING
        });

        return stack;
    }
}

NewRelic Lambda Extension Support

By Default, each lambda will be instrumented with NewRelic's Lambda Extension. This will send more detailed information to NewRelic about the lambda. If you do not wish to do this, in each lambda definition, there is a includeNewRelicExtension setting. Setting this to false will not install the layer for the particular lambda.

NewRelic Prerequisites

In order for the NewRelic extension to work, there are a few prerequisites. These are outlined below:

  • A Role with Trust Relationship setup to account 754728514883. This is NewRelic's account. This Role should be setup by CBO in our account and have the following: ReadOnlyAccess AWS Managed Policy and
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "budgets:ViewBudget"
            ],
            "Resource": "*"
        }
    ]
}

In our L1 accounts, this role is called SvcNewRelicInfrastructure-Integrations

Here is the command once you've installed the newrelic-lambda and placed our files on top of theirs to apply to the account. This has been done for awsdrst and awsdrstnp

newrelic-lambda integrations install --nr-account-id 1840109 --linked-account-name awsdrstnp --nr-api-key <nr userapikey> --enable-license-key-secret --role-name acct-managed/cai-dr-lambda-execution-role 
  • newrelic-log-ingestion will also be created by the process above.
  • cai-dr-lambda-execution-role (lambda execution role) needs the following policy so it can read secrets:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "secretsmanager:GetSecretValue",
            "Resource": [
                "arn:aws:secretsmanager:us-east-1:<accountId>:secret:*"
            ]
        }
    ]
}
  • SSM Parameter Store needs to be setup with /dr/global/services/newrelic/* as defined in the "Parameter Store Dependencies" section below. This has been done for awsdrst and awsdrstnp

Parameter Store Dependencies

KeyConstructDescription
/dr/global/services/splunk-forwarder/drLambdaStackDR Lambda used to forward logs to splunk
/dr/global/services/newrelic/environmentVariables/NEW_RELIC_ACCOUNT_ID'LambdaStackNewRelic Account ID
/dr/global/services/newrelic/environmentVariables/NEW_RELIC_EXTENSION_SEND_FUNCTION_LOGSLambdaStackNewRelic flag for sending function logs
/dr/global/services/newrelic/environmentVariables/NEW_RELIC_LAMBDA_EXTENSION_ENABLEDNewRelic flag to enable the extension
/dr/global/services/newrelic/extensions/{runtime}LambdaStackNewRelic Lambda Extension Layer ARN. {runtime} is the name of the runtime, for instance, nodejs14.x. We have setup Node 10, 12 and 14.
/dr/global/services/newrelic/handlerLambdaStackNewRelic Extension Handler. NR uses this as the handler function which proxies to our actual handler.
/dr/global/services/pipeline-tools/create-or-update-alias/lambda-arnLambdaMoveAliasToVersionManagerFind the lambda to use to move an alias
1.153.1

2 years ago

1.153.2-alpha.0

2 years ago

1.143.42

2 years ago

1.143.41

2 years ago

1.143.44

2 years ago

1.143.43

2 years ago

1.143.42-alpha.0

2 years ago

1.143.42-alpha.1

2 years ago

1.143.37-alpha.3

2 years ago

1.143.37-alpha.2

2 years ago

1.143.37-alpha.0

2 years ago

1.143.40

2 years ago

1.143.39

2 years ago

1.143.38

2 years ago

1.143.35

2 years ago

1.143.37

2 years ago

1.143.36

2 years ago

1.143.14-alpha.0

2 years ago

1.143.26-alpha.9

2 years ago

1.143.26-alpha.7

2 years ago

1.143.26-alpha.6

2 years ago

1.143.26-alpha.1

2 years ago

1.143.26-alpha.0

2 years ago

1.143.32-alpha.2

2 years ago

1.143.32-alpha.1

2 years ago

1.143.26-alpha.4

2 years ago

1.143.32-alpha.0

2 years ago

1.143.26-alpha.3

2 years ago

1.143.32-alpha.4

2 years ago

1.143.32-alpha.3

2 years ago

1.143.11-alpha.0

2 years ago

1.143.31

2 years ago

1.143.30

2 years ago

1.143.32

2 years ago

1.143.28

2 years ago

1.143.27

2 years ago

1.143.29

2 years ago

1.143.31-alpha.3

2 years ago

1.143.24

2 years ago

1.143.31-alpha.2

2 years ago

1.143.23

2 years ago

1.143.31-alpha.1

2 years ago

1.143.26

2 years ago

1.143.31-alpha.0

2 years ago

1.143.25

2 years ago

1.143.22

2 years ago

1.143.21

2 years ago

1.143.31-alpha.4

2 years ago

1.143.14

2 years ago

1.143.13-alpha.0

2 years ago

1.143.21-alpha.4

2 years ago

1.143.21-alpha.3

2 years ago

1.143.21-alpha.6

2 years ago

1.143.21-alpha.5

2 years ago

1.143.21-alpha.8

2 years ago

1.143.21-alpha.7

2 years ago

1.143.21-alpha.9

2 years ago

1.143.21-alpha.0

2 years ago

1.143.21-alpha.2

2 years ago

1.143.21-alpha.1

2 years ago

1.143.12-alpha.0

2 years ago

1.143.8-alpha.0

2 years ago

1.143.30-alpha.2

2 years ago

1.143.30-alpha.0

2 years ago

1.143.5-alpha.0

2 years ago

1.143.5

2 years ago

1.143.4-alpha.0

2 years ago

1.113.11-alpha.0

2 years ago

1.113.4-alpha.0

2 years ago

1.113.8-alpha.0

2 years ago

1.111.0

2 years ago

1.113.10-alpha.0

2 years ago

1.113.1-alpha.0

2 years ago

1.113.5-alpha.0

2 years ago

1.113.9-alpha.0

2 years ago

1.114.0

2 years ago

1.143.1

2 years ago

1.143.2

2 years ago

1.113.2-alpha.0

2 years ago

1.113.6-alpha.0

2 years ago

1.143.3

2 years ago

1.113.12-alpha.0

2 years ago

1.113.0

2 years ago

1.113.7-alpha.0

2 years ago

1.113.3-alpha.0

2 years ago

1.105.3-alpha.0

3 years ago

1.105.6-alpha.0

3 years ago

1.106.0

3 years ago

1.105.2-alpha.0

3 years ago

1.105.5-alpha.0

3 years ago

1.105.0

3 years ago

1.105.1-alpha.0

3 years ago

1.105.4-alpha.0

3 years ago

1.100.1-alpha.0

3 years ago

1.95.1-alpha.0

3 years ago

1.97.0

3 years ago

1.96.0

3 years ago

1.99.0

3 years ago

1.100.0

3 years ago

1.95.0

3 years ago

1.91.0

3 years ago

1.89.0

3 years ago

1.83.0

3 years ago

1.82.1-alpha.0

3 years ago

1.79.0

3 years ago

1.82.0

3 years ago

1.78.0

3 years ago

1.76.1-alpha.0

3 years ago

1.77.0

3 years ago

1.75.1-alpha.0

3 years ago

1.75.0

3 years ago

1.76.0

3 years ago

1.71.0

3 years ago

1.69.0

3 years ago

1.68.18-alpha.0

3 years ago

1.68.12-alpha.0

3 years ago

1.68.7-alpha.0

3 years ago

1.68.14-alpha.0

3 years ago

1.68.9-alpha.0

3 years ago

1.68.3-alpha.0

3 years ago

1.68.1-alpha.0

3 years ago

1.67.0

3 years ago

1.68.0

3 years ago

1.64.6-alpha.0

3 years ago

1.65.0

3 years ago

1.64.5-alpha.0

3 years ago

1.64.4-alpha.0

3 years ago

1.64.1-alpha.0

3 years ago

1.64.2-alpha.0

3 years ago

1.64.3-alpha.0

3 years ago

1.60.0

3 years ago

1.59.0

3 years ago

1.58.9-alpha.0

3 years ago

1.58.8-alpha.0

3 years ago

1.58.6-alpha.0

3 years ago

1.58.7-alpha.0

3 years ago

1.58.5-alpha.0

3 years ago

1.58.2-alpha.0

3 years ago

1.58.4-alpha.0

3 years ago

1.58.1-alpha.0

3 years ago

1.58.0

3 years ago

1.57.0

3 years ago

1.56.0

3 years ago

1.55.0

3 years ago

1.53.1-alpha.0

3 years ago

1.54.0

3 years ago

1.53.0

3 years ago

1.51.4-alpha.0

3 years ago

1.52.0

3 years ago

1.51.3-alpha.0

3 years ago

1.51.2-alpha.0

3 years ago

1.51.0

3 years ago

1.51.1-alpha.0

3 years ago

1.50.0

3 years ago

1.49.0-alpha.0

3 years ago

1.48.0

3 years ago

1.47.0

3 years ago

1.46.0

3 years ago

1.44.1-alpha.0

3 years ago

1.44.0

3 years ago

1.45.0

3 years ago

1.44.2-alpha.0

3 years ago

1.43.5-alpha.0

3 years ago

1.43.3-alpha.0

3 years ago

1.43.1-alpha.0

3 years ago

1.41.1-alpha.0

3 years ago

1.42.0

3 years ago

1.43.0

3 years ago

1.41.0

3 years ago

1.40.1-alpha.0

3 years ago

1.37.0

3 years ago

1.39.0

3 years ago

1.35.0

3 years ago

1.36.0

3 years ago

1.34.0

3 years ago

1.33.0

3 years ago

1.32.0

3 years ago

1.30.0

3 years ago

1.29.0

3 years ago

1.28.0

3 years ago

1.27.0

3 years ago

1.26.0

3 years ago

1.25.0

3 years ago

1.23.0

4 years ago

1.22.0

4 years ago

1.24.0

4 years ago

1.19.0

4 years ago

1.20.0

4 years ago

1.18.0

4 years ago

1.17.0

4 years ago

1.16.0

4 years ago

1.15.0

4 years ago

1.14.0

4 years ago

1.13.0

4 years ago

1.12.0

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.6.1-alpha.2

4 years ago

1.6.1-alpha.1

4 years ago

1.6.0

4 years ago

1.4.0

4 years ago

1.5.0

4 years ago

1.6.1-alpha.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.7-alpha.8

4 years ago

1.1.7-alpha.7

4 years ago

1.1.7-alpha.6

4 years ago

1.1.7-alpha.5

4 years ago

1.1.7-alpha.4

4 years ago

1.1.7-alpha.3

4 years ago

1.1.7-alpha.2

4 years ago

1.1.7-alpha.0

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.1-alpha.7

4 years ago

1.1.0

4 years ago

1.0.1-alpha.44

4 years ago

1.0.1-alpha.42

4 years ago

1.0.1-alpha.41

4 years ago

1.0.1-alpha.38

4 years ago

1.0.1-alpha.35

4 years ago

1.0.1-alpha.34

4 years ago

1.0.1-alpha.33

4 years ago

1.0.1-alpha.31

4 years ago

1.0.1-alpha.24

4 years ago

1.0.1-alpha.15

4 years ago

1.0.1-alpha.14

4 years ago

1.0.1-alpha.13

4 years ago

1.0.1-alpha.23

4 years ago

1.0.1-alpha.12

4 years ago

1.0.1-alpha.19

4 years ago

1.0.1-alpha.18

4 years ago

1.0.1-alpha.16

4 years ago

1.0.1-alpha.22

4 years ago

1.0.1-alpha.21

4 years ago

1.0.1-alpha.20

4 years ago

1.0.1-alpha.11

4 years ago

1.0.1-alpha.10

4 years ago

1.0.1-alpha.9

4 years ago

1.0.1-alpha.6

4 years ago

1.0.1-alpha.5

4 years ago

1.0.1-alpha.8

4 years ago

1.0.1-alpha.7

4 years ago

1.0.1-alpha.3

4 years ago

1.0.1-alpha.2

4 years ago

1.0.1-alpha.1

4 years ago

1.0.1-alpha.0

4 years ago