aws nodejs sdk putObjectAcl correct syntax - node.js

I need to assign public read access and in the same time to allow owner to operate an object with full access after I process the object within the sharp() lib. So, I replace the old object with a new one and thus I need to set new ACL. The ACL allows to have only one type of access and I need kind of to combine
"public-read" and "bucket-owner-full-controll"
According to the interface and documentation this is enough
await s3Bucket.putObjectAcl({
Bucket: s3EventMessage.bucket.name,
Key: key,
AccessControlPolicy: {},
GrantFullControl: 'canonical_id',
GrantRead: 'http://acs.amazonaws.com/groups/global/AllUsers'
}).promise();
Also, I tried this, it should be enough according to the interface, but I'm getting errors:
Bucket: s3EventMessage.bucket.name,
Key: key,
AccessControlPolicy: {
Grants: [
{
Grantee: {
Type: "CanonicalUser"
},
},
],
},
GrantRead: 'http://acs.amazonaws.com/groups/global/AllUsers'
Also I tried this way, I get an error that my XML has wrong format
await s3Bucket.putObjectAcl({
Bucket: s3EventMessage.bucket.name,
Key: key,
AccessControlPolicy: {
Grants: [
{
Grantee: {
Type: "CanonicalUser",
DisplayName: 'Owner',
ID: 'canonical_id',
},
Permission: "FULL_CONTROL"
},
{
Grantee: {
Type: "Group",
URI: 'http://acs.amazonaws.com/groups/global/AllUsers',
},
Permission: "READ",
}
],
},
}).promise();
The error:
MalformedACLError: The XML you provided was not well-formed or did not validate against our published schema
This syntax with a precise owner:
await s3Bucket.putObjectAcl({
Bucket: s3EventMessage.bucket.name,
Key: key,
AccessControlPolicy: {
Owner: {
DisplayName: 'Owner',
ID: 'canonical_id',
},
Grants: [
{
Grantee: {
Type: "CanonicalUser",
DisplayName: 'Owner',
ID: 'canonical_id',
},
Permission: "FULL_CONTROL"
},
{
Grantee: {
Type: "Group",
URI: 'http://acs.amazonaws.com/groups/global/AllUsers',
},
Permission: "READ",
}
],
},
}).promise();
gives an error :
AccessDenied: Access Denied
also, I found a solution in PHP, but that didn't work for me - I'm getting access denied
this is the solution
this is the doc Nodejs example
Thanks in advance!

After some investigation and playing around I figured out what I need:
The lambda had to have a permission related to the bucket: s3:PutObject*
This snippet works perfectly for my task:
await s3Bucket.putObjectAcl({
Bucket: bucket.name,
Key: key,
AccessControlPolicy: {
Owner: {
DisplayName: 'Owner',
ID: 'canonical_id',
},
Grants: [
{
Grantee: {
Type: "CanonicalUser",
DisplayName: 'Owner',
ID: 'canonical_id',
},
Permission: "FULL_CONTROL"
},
{
Grantee: {
Type: "Group",
URI: 'http://acs.amazonaws.com/groups/global/AllUsers',
},
Permission: "READ",
}
],
},
}).promise();

Related

How to push transaction EOS Blockchain (eosjs - unsatisfied_authorization)?

I use Anchor Wallet.
This is init code
const privateKeys = ["myprivatekey"];
const signatureProvider = new JsSignatureProvider(privateKeys);
const rpc = new JsonRpc(config.mainnet, { fetch });
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
return {rpc, api};
Then i try to push transaction
const transaction = await api.transact({
actions: [{
account: 'eosio',
name: 'buyrambytes',
authorization: [{
actor: 'username',
permission: 'active',
}],
data: {
payer: 'username',
receiver: 'username',
bytes: 8192,
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
(docs example)
and receive error
details: [
{
message: `transaction declares authority '{"actor":"username","permission":"active"}', but does not have signatures for it.`,
file: 'authorization_manager.cpp',
line_number: 643,
method: 'get_required_keys'
}
],
json: {
code: 401,
message: 'UnAuthorized',
error: {
code: 3090003,
name: 'unsatisfied_authorization',
what: 'Provided keys, permissions, and delays do not satisfy declared authorizations',
details: [Array]
}
}
}
Maybe i enter wrong private key (Anchor -> Export private key -> Copy key) or something else, idk.
All other functions (for exampe get_block etc.) works fine
try with owner:
authorization: [{
actor: 'username',
permission: 'owner',
}],

Creating AWS S3 object life cycle using NodeJS

Creating AWS S3 object life cycle using NodeJS.
I want to create S3 object life cycle via API using NodeJS. When I see the documentation, AWS provided only multiple object life cycle, with Java.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html
I also checked this url -
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketLifecycle-property
Genral Concern
How to set multiple Transition with NodeJS like the way Java has ?
BucketLifecycleConfiguration.Rule rule2 = new BucketLifecycleConfiguration.Rule()
.withId("Archive and then delete rule")
.withFilter(new LifecycleFilter(new LifecycleTagPredicate(new Tag("archive", "true"))))
.addTransition(new Transition().withDays(30).withStorageClass(StorageClass.StandardInfrequentAccess))
.addTransition(new Transition().withDays(365).withStorageClass(StorageClass.Glacier))
.withExpirationInDays(3650)
.withStatus(BucketLifecycleConfiguration.ENABLED);
Followed by -
https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html
Any help would be great.
we need to call putBucketLifecycle and pass Rules Array to LifecycleConfiguration. Similar to CLI Example
s3.putBucketLifecycle(
{
Bucket: "sample-temp-bucket",
LifecycleConfiguration: {
Rules: [
{
Filter: {
And: {
Prefix: "myprefix",
Tags: [
{
Value: "mytagvalue1",
Key: "mytagkey1",
},
{
Value: "mytagvalue2",
Key: "mytagkey2",
},
],
},
},
Status: "Enabled",
Expiration: {
Days: 1,
},
},
{
Filter: {
Prefix: "documents/",
},
Status: "Enabled",
Transitions: [
{
Days: 365,
StorageClass: "GLACIER",
},
],
Expiration: {
Days: 3650,
},
ID: "ExampleRule",
},
],
},
},
(error, result) => {
if (error) console.log("error", error);
if (result) console.log("result", result);
}
);

How to send Email with FileAttachment from local disk

I am using node-ews for sending Email through MicroSoft Exchange using my corporate credendials.
But I cannot figure out how to attach .xlsx files to an email from local disk storage. It seems that there is no simple Path tag.
This is what i have
const ewsArgs = {
attributes: {
MessageDisposition: 'SendAndSaveCopy',
},
SavedItemFolderId: {
DistinguishedFolderId: {
attributes: {
Id: 'sentitems',
},
},
},
Items: {
Message: {
ItemClass: 'IPM.Note',
Subject: 'Subject',
Body: {
attributes: {
BodyType: 'Text',
},
$value: 'Bodytext',
},
ToRecipients: {
Mailbox: {
EmailAddress: 'email#email.ru',
},
},
IsRead: 'false',
Attachments: {
FileAttachment: [{
Name: 'filename.xlsx',
IsInline: false,
ContentType: 'text/xlsx',
ContentLocation: 'filename.xlsx',
}]
}
},
},
};
What am I doing wrong?
Check your contentLocation. You need to give the correct path of the file you want to attach. But you just provided the filename.
Content-Type: application/vnd.ms-excel

TagSpecifications with requestSpotInstances UnexpectedParameter with aws-sdk

I'm trying to add a tag to my AWS Spot Request. But it has returned me { UnexpectedParameter: Unexpected key 'TagSpecifications' found in params.LaunchSpecification.
I have followed this documentation, and I have already tried to move this code out of LaunchSpecification, but the error persists.
const params = {
InstanceCount: 1,
LaunchSpecification: {
ImageId: config.aws.instanceAMI,
KeyName: 'backoffice',
InstanceType: config.aws.instanceType,
SecurityGroupIds: [config.aws.instanceSecurityGroupId],
TagSpecifications: [{
ResourceType: 'instance',
Tags: [{
Key: 'Type',
Value: 'Mongo-Dump',
}],
}],
BlockDeviceMappings: [{
DeviceName: '/dev/xvda',
Ebs: {
DeleteOnTermination: true,
SnapshotId: 'snap-06e838ce2a80337a4',
VolumeSize: 50,
VolumeType: 'gp2',
Encrypted: false,
},
}],
IamInstanceProfile: {
Name: config.aws.instanceProfileIAMName,
},
Placement: {
AvailabilityZone: `${config.aws.region}a`,
},
},
SpotPrice: config.aws.instancePrice,
Type: 'one-time',
};
return ec2.requestSpotInstances(params).promise();
Something makes me think that the problem is in the documentation or in the aws-sdk for Javascript itself. My options are exhausted.
The error message is correct. According to the documentation, the RequestSpotLaunchSpecification object doesn't have an attribute called TagSpecifications.
However, you can tag your Spot Instance request after you create it.
ec2.requestSpotInstances(params) returns an array of SpotInstanceRequest objects, each containing a spotInstanceRequestId (e.g. sir-012345678). Use the CreateTags API with these Spot Instance request ids to add the tags.
const createTagParams = {
Resources: [ 'sir-12345678' ],
Tags: [
{
Key: 'Type',
Value: 'Mongo-Dump'
}
]
};
ec2.createTags(createTagParams, function(err, data) {
// ...
});

how to get the particular value from the response array received after wallet creation in bitgo Js

This is my array and want to get values from it:
{ wallet:
Wallet {
bitgo:
BitGo {
_baseUrl: 'https://test.bitgo.com',
env: 'test',
_baseApiUrl: 'https://test.bitgo.com/api/v1',
del: [Function] },
baseCoin:
BaseCoin {
network: [Object],
coinKeychains: [Keychains] },
_wallet:
{ id: '5b055bae749a9ba207410c65ff58c325',
users: [Array],
coin: 'tltc',
label: 'My Test Wallet',
m: 2,
n: 3,
pendingApprovals: [] } },
userKeychain:
{ id: '47i3ygdhfhdhjfj84378r'
users: [ '3w65gsdhfgshg93w2r2839'],
pub: 'zsnadfsheg94t854tidghfhdhgdhh kladjfghgdhfhdhfghdhhfghgh',
ethAddress: '0xzxder4tewre79618eceret3a2eabf6c8',
encryptedPrv: '{}',
prv: ' },
backupKeychain:
{ id: '54idhjfhdj9a9ba207410c505912c1b1',
users: [ '90jdfjgbja7007sdjbgjffc7a5065006' ],
pub: '',
ethAddress: '0x753ce0sdfvsdsgdf8baef8sdfesdfssfs2bdd8cb',
prv: '',
source: 'backup' },
bitgoKeychain:
{ id: '5b055bad39230ccc07814e0589388100',
users: [ '5ac1fd5563fa7007d5a17fc7a5065006' ],
pub: '',
ethAddress: '0xbfdgfdgdfdgfhfgtr6756ghfghfg719320fcc7e',
isBitGo: true },
}
// here want to get userKeychain, backupKeychain and bitgoKeychainPlease help how to fetch the this value. Is there any function to access this values or need any parsing method in bitgo Js.
You can get it using like : wallet.wallet._wallet.id
This will give you the wallet id.To get the userKeychain value use like wallet.userKeychain

Resources