Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ahzia committed Jul 22, 2022
1 parent d781ebf commit b0f1e7d
Show file tree
Hide file tree
Showing 40 changed files with 7,085 additions and 10 deletions.
10 changes: 4 additions & 6 deletions packages/@aws-cdk/aws-lambda/lib/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import * as iam from '@aws-cdk/aws-iam';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3_assets from '@aws-cdk/aws-s3-assets';
import * as cdk from '@aws-cdk/core';
import { zipDirectories } from './private/archive';
const fs = require("fs");
const path = require("path");
import { Construct } from 'constructs';
import { zipDirectories } from './private/archive';

/**
* Represents the Lambda Handler Code.
Expand Down Expand Up @@ -53,7 +51,7 @@ export abstract class Code {
*
* @param path Either a directory with the Lambda code bundle or a .zip file
*/
public static fromAsset(path: string, options?: s3_assets.AssetOptions): AssetCode {
public static fromAsset(path: string, options?: s3_assets.AssetOptions): AssetCode {
return new AssetCode(path, options);
}

Expand All @@ -62,9 +60,9 @@ export abstract class Code {
*
* @param paths an array of directories with the Lambda code bundle
*/
public static async fromMultiAsset(paths: [], options?: s3_assets.AssetOptions): Promise<AssetCode> {
public static async fromMultiAsset(paths: string[], options?: s3_assets.AssetOptions): Promise<AssetCode> {
//create a zip file from paths in paths[]
const outputFileAddress = '/cdk.out/directories.zip';
const outputFileAddress = './cdk.out/directories.zip';
await zipDirectories(paths, outputFileAddress);
return new AssetCode(outputFileAddress, options);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-lambda/lib/private/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as glob from 'glob';
// eslint-disable-next-line @typescript-eslint/no-require-imports
const archiver = require('archiver');

export function zipDirectories(directories: [], outputFile: string): Promise<void> {
export function zipDirectories(directories: string[], outputFile: string): Promise<void> {
return new Promise(async (ok, fail) => {

const output = createWriteStream(outputFile);
Expand All @@ -21,7 +21,7 @@ export function zipDirectories(directories: [], outputFile: string): Promise<voi
output.once('close', ok);

archive.pipe(output);
for(const directory of directories) {
for (const directory of directories) {
// The below options are needed to support following symlinks when building zip files:
// - nodir: This will prevent symlinks themselves from being copied into the zip.
// - follow: This will follow symlinks and copy the files within.
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
"@aws-cdk/core": "0.0.0",
"@aws-cdk/cx-api": "0.0.0",
"@aws-cdk/region-info": "0.0.0",
"constructs": "^10.0.0",
"archiver": "^5.3.1"
"@types/archiver": "^5.3.1",
"constructs": "^10.0.0"
},
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def main(event, context):
return {
'message': 'Hello, world!'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"20.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "20.0.0",
"files": {
"9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232": {
"source": {
"path": "asset.9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"b7318e1b9cb46d3116b3092ae8d67eeb76f991783ed974f75c3199bbcccc1847": {
"source": {
"path": "lambda-test-assets.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "b7318e1b9cb46d3116b3092ae8d67eeb76f991783ed974f75c3199bbcccc1847.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"Resources": {
"MyLambdaServiceRole4539ECB6": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"MyLambdaCCE802FB": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "9678c34eca93259d11f2d714177347afd66c50116e1e08996eff893d3ca81232.zip"
},
"Role": {
"Fn::GetAtt": [
"MyLambdaServiceRole4539ECB6",
"Arn"
]
},
"Handler": "index.main",
"Runtime": "python3.9"
},
"DependsOn": [
"MyLambdaServiceRole4539ECB6"
]
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"version": "20.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"lambda-test-assets.assets": {
"type": "cdk:asset-manifest",
"properties": {
"file": "lambda-test-assets.assets.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"lambda-test-assets": {
"type": "aws:cloudformation:stack",
"environment": "aws://unknown-account/unknown-region",
"properties": {
"templateFile": "lambda-test-assets.template.json",
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/b7318e1b9cb46d3116b3092ae8d67eeb76f991783ed974f75c3199bbcccc1847.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
"lambda-test-assets.assets"
],
"lookupRole": {
"arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}",
"requiresBootstrapStackVersion": 8,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version"
}
},
"dependencies": [
"lambda-test-assets.assets"
],
"metadata": {
"/lambda-test-assets/MyLambda/ServiceRole/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "MyLambdaServiceRole4539ECB6"
}
],
"/lambda-test-assets/MyLambda/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "MyLambdaCCE802FB"
}
],
"/lambda-test-assets/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/lambda-test-assets/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
]
},
"displayName": "lambda-test-assets"
}
}
}
Loading

0 comments on commit b0f1e7d

Please sign in to comment.