Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ async function create(event, context) {
return (await iam.send(new ListAttachedRolePoliciesCommand({ RoleName: roleName })))
.AttachedPolicies;
} catch (error) {
if (
error.code === 'NoSuchEntity' ||
error.message.includes('cannot be found')
) {
if (error.code === 'NoSuchEntity' || error.message.includes('cannot be found')) {
// Role doesn't exist yet, create;
await iam.send(
new CreateRoleCommand({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ module.exports = {
let endpointType = 'EDGE';
let vpcEndpointIds;
let BinaryMediaTypes;
let SecurityPolicy;
if (apiGateway.binaryMediaTypes) {
BinaryMediaTypes = apiGateway.binaryMediaTypes;
}

if (apiGateway.securityPolicy) {
SecurityPolicy = apiGateway.securityPolicy;
}

if (this.serverless.service.provider.endpointType) {
endpointType = this.serverless.service.provider.endpointType.toUpperCase();

Expand Down Expand Up @@ -52,6 +57,7 @@ module.exports = {
BinaryMediaTypes,
DisableExecuteApiEndpoint,
EndpointConfiguration,
SecurityPolicy,
};

// Tags
Expand Down
3 changes: 3 additions & 0 deletions lib/plugins/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ class AwsProvider {
type: 'array',
items: { type: 'string', pattern: '^\\S+\\/\\S+$' },
},
securityPolicy: {
type: 'string',
},
description: { type: 'string' },
disableDefaultEndpoint: { type: 'boolean' },
metrics: { type: 'boolean' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ describe('#compileRestApi()', () => {
EndpointConfiguration: {
Types: ['EDGE'],
},
SecurityPolicy: undefined,
Policy: '',
},
});
});

it('should create a REST API resource with security policy', () => {
awsCompileApigEvents.serverless.service.provider.apiGateway = {
securityPolicy: 'SecurityPolicy_TLS13_1_3_2025_09',
};
awsCompileApigEvents.compileRestApi();
const resources =
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources;

expect(resources.ApiGatewayRestApi).to.deep.equal({
Type: 'AWS::ApiGateway::RestApi',
Properties: {
BinaryMediaTypes: undefined,
DisableExecuteApiEndpoint: undefined,
Name: 'dev-new-service',
EndpointConfiguration: {
Types: ['EDGE'],
},
SecurityPolicy: 'SecurityPolicy_TLS13_1_3_2025_09',
Policy: '',
},
});
Expand All @@ -75,6 +99,7 @@ describe('#compileRestApi()', () => {
EndpointConfiguration: {
Types: ['EDGE'],
},
SecurityPolicy: undefined,
Policy: '',
Tags: [
{ Key: 'tagKey1', Value: 'tagValue1' },
Expand Down Expand Up @@ -113,6 +138,7 @@ describe('#compileRestApi()', () => {
EndpointConfiguration: {
Types: ['EDGE'],
},
SecurityPolicy: undefined,
Policy: {
Version: '2012-10-17',
Statement: [
Expand Down Expand Up @@ -148,6 +174,7 @@ describe('#compileRestApi()', () => {
Types: ['EDGE'],
},
Policy: '',
SecurityPolicy: undefined,
},
});
});
Expand Down Expand Up @@ -181,6 +208,7 @@ describe('#compileRestApi()', () => {
},
Name: 'dev-new-service',
Policy: '',
SecurityPolicy: undefined,
},
});
});
Expand Down