Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit23570e1

Browse files
authored
fix internal Serverless custom resources S3 path addressing (#209)
1 parent3050f61 commit23570e1

File tree

4 files changed

+71
-7
lines changed

4 files changed

+71
-7
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ custom:
205205
206206
## Change Log
207207
208+
* v1.0.3: Set S3 Path addressing for internal Serverless Custom Resources - allow configuring S3 Events Notification for functions
208209
* v1.0.2: Add check to prevent IPv6 connection issue with `localhost` on MacOS
209210
* v1.0.1: Add support for Serverless projects with esbuild source config; enable config via environment variables
210211
* v1.0.0: Allow specifying path for mountCode, to point to a relative Lambda mount path

‎package-lock.json‎

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"serverless-localstack",
3-
"version":"1.0.2",
3+
"version":"1.0.3",
44
"description":"Connect Serverless to LocalStack!",
55
"main":"src/index.js",
66
"scripts": {
@@ -25,14 +25,16 @@
2525
"Waldemar Hummer (whummer)",
2626
"Justin McCormick <me@justinmccormick.com>",
2727
"djKooks",
28-
"yohei1126"
28+
"yohei1126",
29+
"bentsku"
2930
],
3031
"license":"MIT",
3132
"bugs": {
3233
"url":"https://github.com/localstack/serverless-localstack/issues"
3334
},
3435
"homepage":"https://github.com/localstack/serverless-localstack",
3536
"dependencies": {
37+
"adm-zip":"^0.5.10",
3638
"aws-sdk":"^2.402.0",
3739
"es6-promisify":"^6.0.1"
3840
},

‎src/index.js‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
constAdmZip=require("adm-zip");
23
constAWS=require('aws-sdk');
34
constfs=require('fs');
45
constpath=require('path');
@@ -49,6 +50,11 @@ class LocalstackPlugin {
4950
// Add a hook to fix TypeError when accessing undefined state attribute
5051
this.addHookInFirstPosition('before:aws:deploy:deploy:checkForChanges',this.beforeDeployCheckForChanges);
5152

53+
constcompileEventsHooks=this.serverless.pluginManager.hooks['package:compileEvents']||[];
54+
compileEventsHooks.push({
55+
pluginName:'LocalstackPlugin',hook:this.patchCustomResourceLambdaS3ForcePathStyle.bind(this)
56+
});
57+
5258
this.awsServices=[
5359
'acm',
5460
'amplify',
@@ -731,7 +737,63 @@ class LocalstackPlugin {
731737
plugin.display=newDisplay;
732738
}
733739
}
740+
patchCustomResourceLambdaS3ForcePathStyle(){
741+
constawsProvider=this.awsProvider;
742+
constpatchMarker=path.join(
743+
awsProvider.serverless.serviceDir,
744+
'.serverless',
745+
'.internal-custom-resources-patched'
746+
);
747+
constzipFilePath=path.join(
748+
awsProvider.serverless.serviceDir,
749+
'.serverless',
750+
awsProvider.naming.getCustomResourcesArtifactName()
751+
);
752+
753+
functionfileExists(filePath){
754+
try{
755+
conststats=fs.statSync(filePath);
756+
returnstats.isFile();
757+
}catch(e){
758+
returnfalse;
759+
}
760+
}
761+
762+
functioncreatePatchMarker(){
763+
try{
764+
fs.open(patchMarker,'a').close()
765+
}catch(err){
766+
return;
767+
}
768+
}
769+
770+
if(fileExists(patchMarker)){
771+
this.debug("serverless-localstack: Serverless internal CustomResources already patched")
772+
return;
773+
}
774+
775+
constcustomResourceZipExists=fileExists(zipFilePath)
734776

777+
if(!customResourceZipExists){
778+
return;
779+
}
780+
781+
constcustomResources=newAdmZip(zipFilePath);
782+
constutilFile=customResources.getEntry('utils.js')
783+
if(utilFile==null)return;
784+
constdata=utilFile.getData().toString()
785+
constpatch="AWS.config.s3ForcePathStyle = true;"
786+
if(data.includes(patch)){
787+
createPatchMarker()
788+
return;
789+
}
790+
constindexPatch=data.indexOf('AWS.config.logger = console;')
791+
constnewData=data.slice(0,indexPatch)+patch+'\n'+data.slice(indexPatch)
792+
utilFile.setData(newData)
793+
customResources.writeZip()
794+
createPatchMarker()
795+
this.debug('serverless-localstack: Serverless internal CustomResources patched')
796+
}
735797
}
736798

737799
module.exports=LocalstackPlugin;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp