Deploying to elastic beanstalk using gulp - Static files permissions issue - amazon-web-services

Recently I've had to change from using eb deploy to using a gulp task to deploy my project to AWS elastic beanstalk.
The reason for this is that I need to babel transform ES6 files to ES5. I don not want to commit the transformed files to our git and eb deploy uses the git-archive command to make the zip to deploy.
The transform and deploy works, I'm running into an issue with static files.
gulp.task('ebDeploy', function() {
return gulp.src([
'./.ebextensions/**', // Include the .ebextensions folder
'./**/*.js', // Match all .js files
'!./es6/**/*', // Exclude files in /es6 dir
'!node_modules', '!node_modules/**', // Exclude the node_modules folder and contained files
'*.js', // Include JS Files in the base dir
'package.json', // Include this specific file in base dir
'./config/**', // Include everything under /config
'./public/**', './public/**/*', // Include everything under /public
'./views/**/*.ejs' // Include all .ejs files under /views
], { base: './' })
.pipe(print())
.pipe(gulpEbDeploy({
//name: 'my-application', // optional: If not set, the name from package.json will be used
//version: '1.0.0', // optional: If not set, the version from package.json will be used
timestamp: true, // optional: If set to false, the zip will not have a timestamp
waitForDeploy: true, // optional: if set to false the task will end as soon as it starts deploying
amazon: {
// accessKeyId: "< your access key (fyi, the 'short' one) >", // optional
// secretAccessKey: "< your secret access key (fyi, the 'long' one) >", // optional
// signatureVersion: "v4", // optional
region: 'eu-west-2',
bucket: 'elasticbeanstalk',
applicationName: 'foo',
environmentName: 'bar'
}
}))
});
I have checked the zip that get's uploaded and it contains all the correct files. However it seems that eb deploy does something to permissions that i need to duplicate.
When I use eb deploy (after committing the /build files which I'm trying to prevent)
Everything works fine.
When I use my gulp task: I get the following error when trying to access static files.
06:49:28.81 server.js:98 | Global Error Handler
06:49:28.81 server.js:99 | { Error: EACCES: permission denied, stat '/var/app/current/public/css/default.css'
at Error (native)
errno: -13,
code: 'EACCES',
syscall: 'stat',
path: '/var/app/current/public/css/default.css',
expose: false,
statusCode: 500,
status: 500 }
What do I need to do to make these files work as intended.

Related

how to use --staging flag in substrate framework?

If i try to run the below command:
./target/release/node-template build-spec --chain staging > stagingSpec.json
facing the below error:
Error: Input("Error opening spec file: No such file or directory (os error 2)")
Is there any guide how to use that staging flag??
Here are the rustdocs for the command, and it's implementation in the node template - this looks for specific from your chain specification file based on what you pass that is configued. In the template at the time of writing, the template only has dev and "everything else" mode:
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()?),
"" | "local" => Box::new(chain_spec::local_testnet_config()?),
path =>
Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
Thus you would need to specify another in/node/src/chainspec.rs and configure the /node/src/commnad.rs to use the correct one when called.

AWS - Centos7 - /home/.aws/credentials not working

I have a Centos7 VPS with AWS CLI installed on the /home directory. I've added my credentials into aws configure and it's generated the following files:
/home/.aws/credentials
/home/.aws/config
If I run the following code, it fails:
$client = new Aws\Lightsail\LightsailClient([
'region' => 'eu-west-2',
'version' => '2016-11-28'
]);
The error message is:
AccessDeniedException (client): User: arn:aws:sts::523423432423:assumed-role/AmazonLightsailInstanceRole/i-0eb5b2155b08e5185 is not authorized to perform
However if I add my credentials like so it works:
$credentials = new Aws\Credentials\Credentials('key', 'secret');
$client = new Aws\Lightsail\LightsailClient([
'region' => 'eu-west-2',
'version' => '2016-11-28',
'credentials' => $credentials
]);
Do I need to do something extra in order to get my script to read the /home/.aws/credentials file?
Do I need to do something extra in order to get my script to read the /home/.aws/credentials file?
Yes, you need to put the .aws/credentials directory in the home directory of the user running the command. This will be something like /home/username instead meaning that the full path to the credentials will be /home/username/.aws/credentials. It does not matter where you installed the aws command to.

AWS-CDK & Powershell Lambda

I have a Powershell Lambda that I would like to deploy via the AWS CDK however I'm having issues getting it to run.
Deploying the Powershell via a manual Publish-AWSPowerShellLambda works:
Publish-AWSPowerShellLambda -ScriptPath .\PowershellLambda.ps1 -Name PowershellLambda
However the same script deployed with the CDK doesnt log to CloudWatch Logs, even though it has permission:
import events = require('#aws-cdk/aws-events');
import targets = require('#aws-cdk/aws-events-targets');
import lambda = require('#aws-cdk/aws-lambda');
import cdk = require('#aws-cdk/core');
export class LambdaCronStack extends cdk.Stack {
constructor(app: cdk.App, id: string) {
super(app, id);
const lambdaFn = new lambda.Function(this, 'Singleton', {
code: new lambda.AssetCode('./PowershellLambda/PowershellLambda.zip'),
handler: 'PowershellLambda::PowershellLambda.Bootstrap::ExecuteFunction',
timeout: cdk.Duration.seconds(300),
runtime: lambda.Runtime.DOTNET_CORE_2_1
});
const rule = new events.Rule(this, 'Rule', {
schedule: events.Schedule.expression('rate(1 minute)')
});
rule.addTarget(new targets.LambdaFunction(lambdaFn));
}
}
const app = new cdk.App();
new LambdaCronStack(app, 'LambdaCronExample');
app.synth();
The powershell script currently contains just the following lines and works when deployed by Publish-AWSPowerShellLambda on the CLI:
#Requires -Modules #{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.335.0'}
Write-Host "Powershell Lambda Executed"
Note: For the CDK Deployment I generate the .zip file using a build step in package.json:
"scripts": {
"build": "tsc",
"build-package": "pwsh -NoProfile -ExecutionPolicy Unrestricted -command New-AWSPowerShellLambdaPackage -ScriptPath './PowershellLambda/PowershellLambda.ps1' -OutputPackage ./PowershellLambda/PowershellLambda.zip",
"watch": "tsc -w",
"cdk": "cdk"
}
The CDK deploys fine and the Lambda runs as expected but the only thing in Cloudwatch Logs is this:
START RequestId: 4c12fe1a-a9e0-4137-90cf-747b6aecb639 Version: $LATEST
I've checked that the Handler in the CDK script matches the output of the Publish-AWSPowerShellLambda and that the zip file uploaded fine and contains the correct code.
Any suggestions as to why this isnt working?
Setting the memory size to 512mb within the lambda.Function has resolved the issue.
The cloudwatch entry showed the lambda starting but it appears there wasn't enough memory to initialize and run the .net runtime.

Error to cloning project with puppet on vagrant

I am trying to install django and clone a github project with a puppet script. I am using modules as follows:
files
(empty directory)
manifests
nodes.pp
web.pp
modules
django
manifests
init.pp
files
(empty directory)
git
manifests
init.pp
files
(empty directory)
postgres
Within the web.pp file I have:
import ' nodes.pp '
In nodes.pp file I have:
node default {
include postgres
include git
include django
}
In init.pp file within the Manifests folder that is inside the git folder I have the following code:
class git{
include git::install
}
class git::install{
package { 'git:':
ensure => present
}
}
define git::clone ( $path, $dir){
exec { "clone-$name-$path":
command => "/usr/bin/git clone git#github.com:$name $path/$dir",
creates => "$path/$dir",
require => [Class["git"], File[$path]],
}
}
In init.pp file within the Manifests folder that is inside the django folder I have the following code:
class django{
include django::install, django::clone, django::environment
}
class django::install {
package { [ "python", "python-dev", "python-virtualenv", "python-pip",
"python-psycopg2", "python-imaging"]:
ensure => present,
}
}
class django::clone {
git::clone { 'My GitHub repository name':
path => '/home/vagrant/',
dir => 'django',
}
}
define django::virtualenv( $path ){
exec { "create-ve-$path":
command => "/usr/bin/virtualenv -q $name",
cwd => $path,
creates => "$path/$name",
require => [Class["django::install"]],
}
}
class django::environment {
django::virtualenv{ 've':
path => '/usr/local/app',
}
}
To run the scripts puppet I use the command:
sudo puppet apply --modulepath=/vagrant/modules /vagrant/manifests/web.pp
and run this command I get the following error:
Could not find dependency File[/home/vagrant/] for
Exec[clone-My GitHub repository name-/home/vagrant/] at
/vagrant/modules/git/manifests/init.pp:16
Note: where is the name 'My GitHub repository name', I put the name of my github repository correctly.
What is wrong and how do I solve this problem?
in your define git::clone have you made sure to declare the file resource for $path?
you should have:
file { $path: ensure => directory }
you can't require a resource that you haven't specifically delcared

Karma's base directory location

Unable to load template fixtures for my tests while using karma. To simplify,
Went to c:\
Created a 1.txt text file.
Made a simple karma init file containing:
basePath: '',
Started karma using:
C:\> karma start .\sample.conf.js
Chrome opened up at:
http://localhost:9876/?id=49209467
I then tried to navigate to:
http://localhost:9876/base/1.txt
but got a "NOT FOUND" error message in the browser, and a message from karma:
WARN [web-server]: 404: /base/1.txt
What am I missing here?
Found the answer:
By adding the following to the karma config file:
files: [
....
{ pattern: 'mocks/**/*.html', watched: true, served: true, included: false },
....
I managed to access the required file by browsing to
http://localhost:9876/base/mocks/file.html
Where th "/base/" prefix is required by default (if even changable).