-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into huijbers/aws-custom-resource-install-latest
- Loading branch information
Showing
452 changed files
with
14,321 additions
and
1,085 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ junit.xml | |
!**/*.snapshot/**/asset.*/*.d.ts | ||
|
||
!**/*.snapshot/**/asset.*/** | ||
!test/integ-assets/**/*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.