Skip to content

Commit

Permalink
Merge branch 'main' into huijbers/aws-custom-resource-install-latest
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 10, 2023
2 parents 2617b5d + 2dfaaf4 commit eb3e6dc
Show file tree
Hide file tree
Showing 452 changed files with 14,321 additions and 1,085 deletions.
438 changes: 219 additions & 219 deletions .github/workflows/issue-label-assign.yml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,8 @@ incompatible-argument:@aws-cdk/aws-route53-targets.InterfaceVpcEndpointTarget.<i
changed-type:@aws-cdk/cx-api.AssetManifestArtifact.requiresBootstrapStackVersion

# removed mistyped ec2 instance class
removed:aws-cdk-lib.aws_ec2.InstanceClass.COMPUTE6_GRAVITON2_HIGH_NETWORK_BANDWITH
removed:aws-cdk-lib.aws_ec2.InstanceClass.COMPUTE6_GRAVITON2_HIGH_NETWORK_BANDWITH

# added new required property StackOutputsMap
strengthened:@aws-cdk/pipelines.ProduceActionOptions
strengthened:aws-cdk-lib.pipelines.ProduceActionOptions
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-apigateway/lib/authorizers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export interface LambdaAuthorizerProps {
/**
* The handler for the authorizer lambda function.
*
* The handler must follow a very specific protocol on the input it receives and the output it needs to produce.
* API Gateway has documented the handler's input specification
* {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html | here} and output specification
* {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html | here}.
* The handler must follow a very specific protocol on the input it receives
* and the output it needs to produce. API Gateway has documented the
* handler's [input specification](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html)
* and [output specification](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html).
*/
readonly handler: lambda.IFunction;

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/lambda-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface LambdaRestApiProps extends RestApiProps {
/**
* Specific Lambda integration options.
*
* @default see defaults defined in {@link LambdaIntegrationOptions}.
* @default see defaults defined in `LambdaIntegrationOptions`.
*/
readonly integrationOptions?: LambdaIntegrationOptions;

Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export interface MethodOptions {
* Method authorization.
* If the value is set of `Custom`, an `authorizer` must also be specified.
*
* If you're using one of the authorizers that are available via the {@link Authorizer} class, such as {@link Authorizer#token()},
* If you're using one of the authorizers that are available via the `Authorizer` class, such as `Authorizer#token()`,
* it is recommended that this option not be specified. The authorizer will take care of setting the correct authorization type.
* However, specifying an authorization type using this property that conflicts with what is expected by the {@link Authorizer}
* However, specifying an authorization type using this property that conflicts with what is expected by the `Authorizer`
* will result in an error.
*
* @default - open access unless `authorizer` is specified
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export abstract class RestApiBase extends Resource implements IRestApi {
/**
* Represents a REST API in Amazon API Gateway, created with an OpenAPI specification.
*
* Some properties normally accessible on @see {@link RestApi} - such as the description -
* Some properties normally accessible on @see `RestApi` - such as the description -
* must be declared in the specification. All Resources and Methods need to be defined as
* part of the OpenAPI specification file, and cannot be added via the CDK.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-appmesh/lib/http-route-path-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Construct } from 'constructs';
import { CfnGatewayRoute, CfnRoute } from './appmesh.generated';

/**
* The type returned from the `bind()` method in {@link HttpRoutePathMatch}.
* The type returned from the `bind()` method in `HttpRoutePathMatch`.
*/
export interface HttpRoutePathMatchConfig {
/**
Expand Down Expand Up @@ -94,7 +94,7 @@ class HttpRouteWholePathMatch extends HttpRoutePathMatch {
}

/**
* The type returned from the `bind()` method in {@link HttpGatewayRoutePathMatch}.
* The type returned from the `bind()` method in `HttpGatewayRoutePathMatch`.
*/
export interface HttpGatewayRoutePathMatchConfig {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appmesh/lib/tls-certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Construct } from 'constructs';
import { CfnVirtualNode } from './appmesh.generated';

/**
* A wrapper for the tls config returned by {@link TlsCertificate.bind}
* A wrapper for the tls config returned by `TlsCertificate.bind`
*/
export interface TlsCertificateConfig {
/**
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-appsync/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ junit.xml
!**/*.snapshot/**/asset.*/*.d.ts

!**/*.snapshot/**/asset.*/**
!test/integ-assets/**/*.js
36 changes: 36 additions & 0 deletions packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,40 @@ const pipelineResolver = new appsync.Resolver(this, 'pipeline', {
});
```

### JS Functions and Resolvers

JS Functions and resolvers are also supported. You can use a `.js` file within your CDK project, or specify your function code inline.

```ts
declare const api: appsync.GraphqlApi;

const myJsFunction = new appsync.AppsyncFunction(this, 'function', {
name: 'my_js_function',
api,
dataSource: api.addNoneDataSource('none'),
code: appsync.Code.fromAsset('directory/function_code.js'),
runtime: appsync.FunctionRuntime.JS_1_0_0,
});

new appsync.Resolver(this, 'PipelineResolver', {
api,
typeName: 'typeName',
fieldName: 'fieldName',
code: appsync.Code.fromInline(`
// The before step
export function request(...args) {
console.log(args);
return {}
}
// The after step
export function response(ctx) {
return ctx.prev.result
}
`),
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [myJsFunction],
});
```

Learn more about Pipeline Resolvers and AppSync Functions [here](https://docs.aws.amazon.com/appsync/latest/devguide/pipeline-resolvers.html).
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-appsync/lib/appsync-function.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Resource, IResource, Lazy, Fn } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnFunctionConfiguration } from './appsync.generated';
import { Code } from './code';
import { BaseDataSource } from './data-source';
import { IGraphqlApi } from './graphqlapi-base';
import { MappingTemplate } from './mapping-template';
import { FunctionRuntime } from './runtime';

/**
* the base properties for AppSync Functions
Expand Down Expand Up @@ -31,6 +33,18 @@ export interface BaseAppsyncFunctionProps {
* @default - no response mapping template
*/
readonly responseMappingTemplate?: MappingTemplate;
/**
* The functions runtime
*
* @default - no function runtime, VTL mapping templates used
*/
readonly runtime?: FunctionRuntime;
/**
* The function code
*
* @default - no code is used
*/
readonly code?: Code;
}

/**
Expand Down Expand Up @@ -128,11 +142,25 @@ export class AppsyncFunction extends Resource implements IAppsyncFunction {

public constructor(scope: Construct, id: string, props: AppsyncFunctionProps) {
super(scope, id);

// If runtime is specified, code must also be
if (props.runtime && !props.code) {
throw new Error('Code is required when specifying a runtime');
}

if (props.code && (props.requestMappingTemplate || props.responseMappingTemplate)) {
throw new Error('Mapping templates cannot be used alongside code');
}

const code = props.code?.bind(this);
this.function = new CfnFunctionConfiguration(this, 'Resource', {
name: props.name,
description: props.description,
apiId: props.api.apiId,
dataSourceName: props.dataSource.name,
runtime: props.runtime?.toProperties(),
codeS3Location: code?.s3Location,
code: code?.inlineCode,
functionVersion: '2018-05-29',
requestMappingTemplate: props.requestMappingTemplate?.renderTemplate(),
responseMappingTemplate: props.responseMappingTemplate?.renderTemplate(),
Expand Down
98 changes: 98 additions & 0 deletions packages/@aws-cdk/aws-appsync/lib/code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as s3_assets from '@aws-cdk/aws-s3-assets';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';

/**
* Result of binding `Code` into a `Function`.
*/
export interface CodeConfig {
/**
* The location of the code in S3 (mutually exclusive with `inlineCode`.
* @default - code is not an s3 location
*/
readonly s3Location?: string;

/**
* Inline code (mutually exclusive with `s3Location`).
* @default - code is not inline code
*/
readonly inlineCode?: string;
}

/**
* Represents source code for an AppSync Function or Resolver.
*/
export abstract class Code {
/**
* Loads the function code from a local disk path.
*
* @param path The path to the source code file.
*/
public static fromAsset(path: string, options?: s3_assets.AssetOptions): AssetCode {
return new AssetCode(path, options);
}

/**
* Inline code for AppSync function
* @returns `InlineCode` with inline code.
* @param code The actual handler code (limited to 4KiB)
*/
public static fromInline(code: string): InlineCode {
return new InlineCode(code);
}

/**
* Bind source code to an AppSync Function or resolver.
*/
public abstract bind(scope: Construct): CodeConfig;
}

/**
* Represents a local file with source code used for an AppSync Function or Resolver.
*/
export class AssetCode extends Code {
private asset?: s3_assets.Asset;

/**
* @param path The path to the asset file.
*/
constructor(public readonly path: string, private readonly options: s3_assets.AssetOptions = { }) {
super();
}

public bind(scope: Construct): CodeConfig {
// If the same AssetCode is used multiple times, retain only the first instantiation.
if (!this.asset) {
this.asset = new s3_assets.Asset(scope, 'Code', {
path: this.path,
...this.options,
});
} else if (cdk.Stack.of(this.asset) !== cdk.Stack.of(scope)) {
throw new Error(`Asset is already associated with another stack '${cdk.Stack.of(this.asset).stackName}'. ` +
'Create a new Code instance for every stack.');
}

return {
s3Location: this.asset.s3ObjectUrl,
};
}
}

/**
* AppSync function code from an inline string.
*/
export class InlineCode extends Code {
constructor(private code: string) {
super();

if (code.length === 0) {
throw new Error('AppSync Inline code cannot be empty');
}
}

public bind(_scope: Construct): CodeConfig {
return {
inlineCode: this.code,
};
}
}
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-appsync/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export * from './resolver';
export * from './schema';
export * from './graphqlapi';
export * from './graphqlapi-base';
export * from './code';
export * from './runtime';
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-appsync/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { IAppsyncFunction } from './appsync-function';
import { CfnResolver } from './appsync.generated';
import { CachingConfig } from './caching-config';
import { BASE_CACHING_KEYS } from './caching-key';
import { Code } from './code';
import { BaseDataSource } from './data-source';
import { IGraphqlApi } from './graphqlapi-base';
import { MappingTemplate } from './mapping-template';
import { FunctionRuntime } from './runtime';

/**
* Basic properties for an AppSync resolver
Expand Down Expand Up @@ -51,6 +53,19 @@ export interface BaseResolverProps {
* @default - No max batch size
*/
readonly maxBatchSize?: number;

/**
* The functions runtime
*
* @default - no function runtime, VTL mapping templates used
*/
readonly runtime?: FunctionRuntime;
/**
* The function code
*
* @default - no code is used
*/
readonly code?: Code;
}

/**
Expand Down Expand Up @@ -93,6 +108,15 @@ export class Resolver extends Construct {
{ functions: props.pipelineConfig.map((func) => func.functionId) }
: undefined;

// If runtime is specified, code must also be
if (props.runtime && !props.code) {
throw new Error('Code is required when specifying a runtime');
}

if (props.code && (props.requestMappingTemplate || props.responseMappingTemplate)) {
throw new Error('Mapping templates cannot be used alongside code');
}

if (pipelineConfig && props.dataSource) {
throw new Error(`Pipeline Resolver cannot have data source. Received: ${props.dataSource.name}`);
}
Expand All @@ -108,12 +132,16 @@ export class Resolver extends Construct {
}
}

const code = props.code?.bind(this);
this.resolver = new CfnResolver(this, 'Resource', {
apiId: props.api.apiId,
typeName: props.typeName,
fieldName: props.fieldName,
dataSourceName: props.dataSource ? props.dataSource.name : undefined,
kind: pipelineConfig ? 'PIPELINE' : 'UNIT',
runtime: props.runtime?.toProperties(),
codeS3Location: code?.s3Location,
code: code?.inlineCode,
pipelineConfig: pipelineConfig,
requestMappingTemplate: props.requestMappingTemplate ? props.requestMappingTemplate.renderTemplate() : undefined,
responseMappingTemplate: props.responseMappingTemplate ? props.responseMappingTemplate.renderTemplate() : undefined,
Expand Down
Loading

0 comments on commit eb3e6dc

Please sign in to comment.