Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcstorms1 committed Oct 26, 2021
1 parent d0c9281 commit 9d7b4d2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-lambda/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export class Function extends FunctionBase {
/**
* The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64).
*/
public readonly architecture: Architecture;
public readonly architecture?: Architecture;
public readonly permissionsNode = this.node;


Expand Down Expand Up @@ -677,7 +677,7 @@ export class Function extends FunctionBase {
if (props.architectures && props.architectures.length > 1) {
throw new Error('Only one architecture must be specified.');
}
const architecture = props.architecture ?? (props.architectures && props.architectures[0]);
const architecture = props.architecture ?? (props.architectures && props.architectures[0]) ?? Architecture.X86_64;

const resource: CfnFunction = new CfnFunction(this, 'Resource', {
functionName: this.physicalName,
Expand Down Expand Up @@ -726,7 +726,7 @@ export class Function extends FunctionBase {

this.runtime = props.runtime;

this.architecture = props.architecture;
this.architecture = architecture;

if (props.layers) {
if (props.runtime === Runtime.FROM_IMAGE) {
Expand Down
29 changes: 27 additions & 2 deletions packages/@aws-cdk/aws-lambda/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ describe('function', () => {
Properties:
{
Code: { ZipFile: 'foo' },
Architectures: [
'x86_64',
],
Handler: 'index.handler',
Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] },
Runtime: 'nodejs10.x',
Expand Down Expand Up @@ -97,6 +100,7 @@ describe('function', () => {
expect(stack).toHaveResource('AWS::Lambda::Function', {
Properties: {
Code: { ZipFile: 'foo' },
Architectures: ['x86_64'],
Handler: 'index.handler',
Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] },
Runtime: 'nodejs10.x',
Expand Down Expand Up @@ -149,6 +153,9 @@ describe('function', () => {
Code: {
ZipFile: 'foo',
},
Architectures: [
'x86_64',
],
Handler: 'bar',
Role: {
'Fn::GetAtt': [
Expand Down Expand Up @@ -393,6 +400,9 @@ describe('function', () => {
]],
},
},
Architectures: [
'x86_64',
],
Handler: 'index.handler',
Role: {
'Fn::GetAtt': [
Expand Down Expand Up @@ -471,6 +481,9 @@ describe('function', () => {
Code: {
ZipFile: 'foo',
},
Architectures: [
'x86_64',
],
Handler: 'index.handler',
Role: {
'Fn::GetAtt': [
Expand Down Expand Up @@ -536,6 +549,9 @@ describe('function', () => {
Code: {
ZipFile: 'foo',
},
Architectures: [
'x86_64',
],
Handler: 'index.handler',
Role: {
'Fn::GetAtt': [
Expand Down Expand Up @@ -699,6 +715,9 @@ describe('function', () => {
'Arn',
],
},
Architectures: [
'x86_64',
],
Runtime: 'nodejs10.x',
TracingConfig: {
Mode: 'Active',
Expand Down Expand Up @@ -748,6 +767,9 @@ describe('function', () => {
Code: {
ZipFile: 'foo',
},
Architectures: [
'x86_64',
],
Handler: 'index.handler',
Role: {
'Fn::GetAtt': [
Expand Down Expand Up @@ -811,6 +833,9 @@ describe('function', () => {
'Arn',
],
},
Architectures: [
'x86_64',
],
Runtime: 'nodejs10.x',
},
DependsOn: [
Expand Down Expand Up @@ -2234,7 +2259,7 @@ describe('function', () => {
handler: 'index.handler',
architecture: lambda.Architecture.ARM_64,
});
expect(fn.architecture.name).toEqual('arm64');
expect(fn.architecture?.name).toEqual('arm64');
});
test('Architecture returns amd64 when no architecture is set', () => {
const stack = new cdk.Stack();
Expand All @@ -2243,7 +2268,7 @@ describe('function', () => {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
});
expect(fn.architecture.name).toEqual('amd64');
expect(fn.architecture?.name).toEqual('x86_64');
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-lambda/test/lambda-insights.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ describe('lambda-insights', () => {
'Arn',
],
},
'Architectures': ['x86_64'],
'Handler': 'index.handler',
'Layers': [
{
Expand Down Expand Up @@ -239,6 +240,7 @@ describe('lambda-insights', () => {
'Arn',
],
},
'Architectures': ['x86_64'],
'Handler': 'index.handler',
'Layers': [
{
Expand Down Expand Up @@ -337,7 +339,7 @@ describe('lambda-insights', () => {
],
},
'ManagedPolicyArns': [
{ },
{},
{
'Fn::Join': [
'',
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-lambda/test/singleton-lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('singleton lambda', () => {
},
Handler: 'index.hello',
Role: { 'Fn::GetAtt': ['SingletonLambda84c0de93353f42179b0b45b6c993251aServiceRole26D59235', 'Arn'] },
Architectures: ['x86_64'],
Runtime: 'python2.7',
Timeout: 300,
},
Expand Down

0 comments on commit 9d7b4d2

Please sign in to comment.